1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 client_menu.c for the Openbox window manager
4 Copyright (c) 2003-2007 Dana Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
21 #include "menuframe.h"
26 #include "moveresize.h"
32 #define CLIENT_MENU_NAME "client-menu"
33 #define SEND_TO_MENU_NAME "client-send-to-menu"
34 #define LAYER_MENU_NAME "client-layer-menu"
55 static gboolean client_menu_update(ObMenuFrame *frame, gpointer data)
57 ObMenu *menu = frame->menu;
60 if (frame->client == NULL || !client_normal(frame->client))
61 return FALSE; /* don't show the menu */
63 for (it = menu->entries; it; it = g_list_next(it)) {
64 ObMenuEntry *e = it->data;
65 gboolean *en = &e->data.normal.enabled; /* save some typing */
66 ObClient *c = frame->client;
68 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL) {
71 *en = c->functions & OB_CLIENT_FUNC_ICONIFY;
74 *en = c->max_horz || c->max_vert;
77 *en = ((c->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
78 (!c->max_horz || !c->max_vert));
81 *en = c->functions & OB_CLIENT_FUNC_SHADE;
84 *en = c->functions & OB_CLIENT_FUNC_MOVE;
87 *en = c->functions & OB_CLIENT_FUNC_RESIZE;
90 *en = c->functions & OB_CLIENT_FUNC_CLOSE;
93 *en = client_normal(c);
100 return TRUE; /* show the menu */
103 static void client_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
104 ObClient *c, guint state, gpointer data,
113 client_iconify(c, TRUE, FALSE);
114 /* the client won't be on screen anymore so hide the menu */
115 menu_frame_hide_all();
116 f = NULL; /* and don't update */
119 client_maximize(c, FALSE, 0);
121 case CLIENT_MAXIMIZE:
122 client_maximize(c, TRUE, 0);
125 client_shade(c, !c->shaded);
127 case CLIENT_DECORATE:
128 client_set_undecorated(c, !c->undecorated);
131 moveresize_start(c,0,0,0, prop_atoms.net_wm_moveresize_move_keyboard);
134 moveresize_start(c,0,0,0,prop_atoms.net_wm_moveresize_size_keyboard);
140 g_assert_not_reached();
143 /* update the menu cuz stuff can have changed */
145 client_menu_update(f, NULL);
146 menu_frame_render(f);
150 static gboolean layer_menu_update(ObMenuFrame *frame, gpointer data)
152 ObMenu *menu = frame->menu;
155 if (frame->client == NULL || !client_normal(frame->client))
156 return FALSE; /* don't show the menu */
158 for (it = menu->entries; it; it = g_list_next(it)) {
159 ObMenuEntry *e = it->data;
160 gboolean *en = &e->data.normal.enabled; /* save some typing */
161 ObClient *c = frame->client;
163 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL) {
169 *en = c->above || c->below;
179 return TRUE; /* show the menu */
182 static void layer_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
183 ObClient *c, guint state, gpointer data,
190 client_set_layer(f->client, 1);
193 client_set_layer(f->client, 0);
196 client_set_layer(f->client, -1);
199 g_assert_not_reached();
202 /* update the menu cuz stuff can have changed */
204 layer_menu_update(f, NULL);
205 menu_frame_render(f);
209 static gboolean send_to_menu_update(ObMenuFrame *frame, gpointer data)
211 ObMenu *menu = frame->menu;
215 menu_clear_entries(menu);
217 if (frame->client == NULL || !client_normal(frame->client))
218 return FALSE; /* don't show the menu */
220 for (i = 0; i <= screen_num_desktops; ++i) {
224 if (i >= screen_num_desktops) {
225 menu_add_separator(menu, -1, NULL);
228 name = _("All desktops");
231 name = screen_desktop_names[i];
234 e = menu_add_normal(menu, desk, name, NULL, FALSE);
236 if (desk == DESKTOP_ALL) {
237 e->data.normal.mask = ob_rr_theme->desk_mask;
238 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
239 e->data.normal.mask_selected_color =
240 ob_rr_theme->menu_selected_color;
241 e->data.normal.mask_disabled_color =
242 ob_rr_theme->menu_disabled_color;
243 e->data.normal.mask_disabled_selected_color =
244 ob_rr_theme->menu_disabled_selected_color;
247 if (frame->client->desktop == desk)
248 e->data.normal.enabled = FALSE;
250 return TRUE; /* show the menu */
253 static void send_to_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
254 ObClient *c, guint state, gpointer data,
259 client_set_desktop(c, e->id, FALSE);
260 /* the client won't even be on the screen anymore, so hide the menu */
262 menu_frame_hide_all();
265 static void client_menu_place(ObMenuFrame *frame, gint *x, gint *y,
266 gint button, gpointer data)
270 if (button == 0 && frame->client) {
271 *x = frame->client->frame->area.x;
273 /* try below the titlebar */
274 *y = frame->client->frame->area.y + frame->client->frame->size.top -
275 frame->client->frame->bwidth;
276 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
278 /* try above the titlebar */
279 *y = frame->client->frame->area.y + frame->client->frame->bwidth -
281 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
284 /* didnt fit either way, use move on screen's values */
285 *y = frame->client->frame->area.y + frame->client->frame->size.top;
286 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
297 /* try to the bottom right of the cursor */
298 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
299 if (dx != 0 || dy != 0) {
300 /* try to the bottom left of the cursor */
301 myx = *x - frame->area.width;
303 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
305 if (dx != 0 || dy != 0) {
306 /* try to the top right of the cursor */
308 myy = *y - frame->area.height;
309 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
311 if (dx != 0 || dy != 0) {
312 /* try to the top left of the cursor */
313 myx = *x - frame->area.width;
314 myy = *y - frame->area.height;
315 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
317 if (dx != 0 || dy != 0) {
318 /* if didnt fit on either side so just use what it says */
321 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
328 void client_menu_startup()
333 menu = menu_new(LAYER_MENU_NAME, _("&Layer"), TRUE, NULL);
334 menu_show_all_shortcuts(menu, TRUE);
335 menu_set_update_func(menu, layer_menu_update);
336 menu_set_execute_func(menu, layer_menu_execute);
338 menu_add_normal(menu, LAYER_TOP, _("Always on &top"), NULL, TRUE);
339 menu_add_normal(menu, LAYER_NORMAL, _("&Normal"), NULL, TRUE);
340 menu_add_normal(menu, LAYER_BOTTOM, _("Always on &bottom"),NULL, TRUE);
343 menu = menu_new(SEND_TO_MENU_NAME, _("&Send to desktop"), TRUE, NULL);
344 menu_set_update_func(menu, send_to_menu_update);
345 menu_set_execute_func(menu, send_to_menu_execute);
347 menu = menu_new(CLIENT_MENU_NAME, _("Client menu"), TRUE, NULL);
348 menu_show_all_shortcuts(menu, TRUE);
349 menu_set_update_func(menu, client_menu_update);
350 menu_set_place_func(menu, client_menu_place);
351 menu_set_execute_func(menu, client_menu_execute);
353 e = menu_add_normal(menu, CLIENT_RESTORE, _("R&estore"), NULL, TRUE);
354 e->data.normal.mask = ob_rr_theme->max_toggled_mask;
355 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
356 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
357 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
358 e->data.normal.mask_disabled_selected_color =
359 ob_rr_theme->menu_disabled_selected_color;
361 menu_add_normal(menu, CLIENT_MOVE, _("&Move"), NULL, TRUE);
363 menu_add_normal(menu, CLIENT_RESIZE, _("Resi&ze"), NULL, TRUE);
365 e = menu_add_normal(menu, CLIENT_ICONIFY, _("Ico&nify"), NULL, TRUE);
366 e->data.normal.mask = ob_rr_theme->iconify_mask;
367 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
368 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
369 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
370 e->data.normal.mask_disabled_selected_color =
371 ob_rr_theme->menu_disabled_selected_color;
373 e = menu_add_normal(menu, CLIENT_MAXIMIZE, _("Ma&ximize"), NULL, TRUE);
374 e->data.normal.mask = ob_rr_theme->max_mask;
375 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
376 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
377 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
378 e->data.normal.mask_disabled_selected_color =
379 ob_rr_theme->menu_disabled_selected_color;
381 e = menu_add_normal(menu, CLIENT_SHADE, _("&Roll up/down"), NULL, TRUE);
382 e->data.normal.mask = ob_rr_theme->shade_mask;
383 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
384 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
385 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
386 e->data.normal.mask_disabled_selected_color =
387 ob_rr_theme->menu_disabled_selected_color;
389 menu_add_normal(menu, CLIENT_DECORATE, _("Un/&Decorate"), NULL, TRUE);
391 menu_add_separator(menu, -1, NULL);
393 menu_add_submenu(menu, CLIENT_SEND_TO, SEND_TO_MENU_NAME);
395 menu_add_submenu(menu, CLIENT_LAYER, LAYER_MENU_NAME);
397 menu_add_separator(menu, -1, NULL);
399 e = menu_add_normal(menu, CLIENT_CLOSE, _("&Close"), NULL, TRUE);
400 e->data.normal.mask = ob_rr_theme->close_mask;
401 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
402 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
403 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
404 e->data.normal.mask_disabled_selected_color =
405 ob_rr_theme->menu_disabled_selected_color;