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"
33 #define CLIENT_MENU_NAME "client-menu"
34 #define SEND_TO_MENU_NAME "client-send-to-menu"
35 #define LAYER_MENU_NAME "client-layer-menu"
56 static gboolean client_menu_update(ObMenuFrame *frame, gpointer data)
58 ObMenu *menu = frame->menu;
61 if (frame->client == NULL || !client_normal(frame->client))
62 return FALSE; /* don't show the menu */
64 for (it = menu->entries; it; it = g_list_next(it)) {
65 ObMenuEntry *e = it->data;
66 gboolean *en = &e->data.normal.enabled; /* save some typing */
67 ObClient *c = frame->client;
69 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL) {
72 *en = c->functions & OB_CLIENT_FUNC_ICONIFY;
75 *en = c->max_horz || c->max_vert;
78 *en = ((c->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
79 (!c->max_horz || !c->max_vert));
82 *en = c->functions & OB_CLIENT_FUNC_SHADE;
85 *en = c->functions & OB_CLIENT_FUNC_MOVE;
88 *en = c->functions & OB_CLIENT_FUNC_RESIZE;
91 *en = c->functions & OB_CLIENT_FUNC_CLOSE;
94 *en = c->functions & OB_CLIENT_FUNC_UNDECORATE;
101 return TRUE; /* show the menu */
104 static void client_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
105 ObClient *c, guint state, gpointer data,
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 */
118 client_iconify(c, TRUE, FALSE, FALSE);
121 client_maximize(c, FALSE, 0);
122 event_ignore_queued_enters();
124 case CLIENT_MAXIMIZE:
125 client_maximize(c, TRUE, 0);
126 event_ignore_queued_enters();
129 client_shade(c, !c->shaded);
130 event_ignore_queued_enters();
132 case CLIENT_DECORATE:
133 client_set_undecorated(c, !c->undecorated);
134 event_ignore_queued_enters();
137 /* this needs to grab the keyboard so hide the menu */
138 menu_frame_hide_all();
139 f = NULL; /* and don't update */
141 screen_pointer_pos(&x, &y);
142 moveresize_start(c, x, y, 0,
143 prop_atoms.net_wm_moveresize_move_keyboard);
146 /* this needs to grab the keyboard so hide the menu */
147 menu_frame_hide_all();
148 f = NULL; /* and don't update */
150 screen_pointer_pos(&x, &y);
151 moveresize_start(c, x, y, 0,
152 prop_atoms.net_wm_moveresize_size_keyboard);
158 g_assert_not_reached();
161 /* update the menu cuz stuff can have changed */
163 client_menu_update(f, NULL);
164 menu_frame_render(f);
168 static gboolean layer_menu_update(ObMenuFrame *frame, gpointer data)
170 ObMenu *menu = frame->menu;
173 if (frame->client == NULL || !client_normal(frame->client))
174 return FALSE; /* don't show the menu */
176 for (it = menu->entries; it; it = g_list_next(it)) {
177 ObMenuEntry *e = it->data;
178 gboolean *en = &e->data.normal.enabled; /* save some typing */
179 ObClient *c = frame->client;
181 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL) {
184 *en = !c->above && (c->functions & OB_CLIENT_FUNC_ABOVE);
187 *en = c->above || c->below;
190 *en = !c->below && (c->functions & OB_CLIENT_FUNC_BELOW);
197 return TRUE; /* show the menu */
200 static void layer_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
201 ObClient *c, guint state, gpointer data,
208 client_set_layer(c, 1);
211 client_set_layer(c, 0);
214 client_set_layer(c, -1);
217 g_assert_not_reached();
220 event_ignore_queued_enters();
222 /* update the menu cuz stuff can have changed */
224 layer_menu_update(f, NULL);
225 menu_frame_render(f);
229 static gboolean send_to_menu_update(ObMenuFrame *frame, gpointer data)
231 ObMenu *menu = frame->menu;
235 menu_clear_entries(menu);
237 if (frame->client == NULL || !client_normal(frame->client))
238 return FALSE; /* don't show the menu */
240 for (i = 0; i <= screen_num_desktops; ++i) {
244 if (i >= screen_num_desktops) {
245 menu_add_separator(menu, -1, NULL);
248 name = _("All desktops");
251 name = screen_desktop_names[i];
254 e = menu_add_normal(menu, desk, name, NULL, FALSE);
256 if (desk == DESKTOP_ALL) {
257 e->data.normal.mask = ob_rr_theme->desk_mask;
258 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
259 e->data.normal.mask_selected_color =
260 ob_rr_theme->menu_selected_color;
261 e->data.normal.mask_disabled_color =
262 ob_rr_theme->menu_disabled_color;
263 e->data.normal.mask_disabled_selected_color =
264 ob_rr_theme->menu_disabled_selected_color;
267 if (frame->client->desktop == desk)
268 e->data.normal.enabled = FALSE;
270 return TRUE; /* show the menu */
273 static void send_to_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
274 ObClient *c, guint state, gpointer data,
279 client_set_desktop(c, e->id, FALSE);
280 /* the client won't even be on the screen anymore, so hide the menu */
282 menu_frame_hide_all();
285 static void client_menu_place(ObMenuFrame *frame, gint *x, gint *y,
286 gint button, gpointer data)
290 if (button == 0 && frame->client) {
291 *x = frame->client->frame->area.x;
293 /* try below the titlebar */
294 *y = frame->client->frame->area.y + frame->client->frame->size.top -
295 frame->client->frame->bwidth;
296 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
298 /* try above the titlebar */
299 *y = frame->client->frame->area.y + frame->client->frame->bwidth -
301 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
304 /* didnt fit either way, use move on screen's values */
305 *y = frame->client->frame->area.y + frame->client->frame->size.top;
306 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
317 /* try to the bottom right of the cursor */
318 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
319 if (dx != 0 || dy != 0) {
320 /* try to the bottom left of the cursor */
321 myx = *x - frame->area.width;
323 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
325 if (dx != 0 || dy != 0) {
326 /* try to the top right of the cursor */
328 myy = *y - frame->area.height;
329 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
331 if (dx != 0 || dy != 0) {
332 /* try to the top left of the cursor */
333 myx = *x - frame->area.width;
334 myy = *y - frame->area.height;
335 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
337 if (dx != 0 || dy != 0) {
338 /* if didnt fit on either side so just use what it says */
341 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
348 void client_menu_startup()
353 menu = menu_new(LAYER_MENU_NAME, _("&Layer"), TRUE, NULL);
354 menu_show_all_shortcuts(menu, TRUE);
355 menu_set_update_func(menu, layer_menu_update);
356 menu_set_execute_func(menu, layer_menu_execute);
358 menu_add_normal(menu, LAYER_TOP, _("Always on &top"), NULL, TRUE);
359 menu_add_normal(menu, LAYER_NORMAL, _("&Normal"), NULL, TRUE);
360 menu_add_normal(menu, LAYER_BOTTOM, _("Always on &bottom"),NULL, TRUE);
363 menu = menu_new(SEND_TO_MENU_NAME, _("&Send to desktop"), TRUE, NULL);
364 menu_set_update_func(menu, send_to_menu_update);
365 menu_set_execute_func(menu, send_to_menu_execute);
367 menu = menu_new(CLIENT_MENU_NAME, _("Client menu"), TRUE, NULL);
368 menu_show_all_shortcuts(menu, TRUE);
369 menu_set_update_func(menu, client_menu_update);
370 menu_set_place_func(menu, client_menu_place);
371 menu_set_execute_func(menu, client_menu_execute);
373 e = menu_add_normal(menu, CLIENT_RESTORE, _("R&estore"), NULL, TRUE);
374 e->data.normal.mask = ob_rr_theme->max_toggled_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 menu_add_normal(menu, CLIENT_MOVE, _("&Move"), NULL, TRUE);
383 menu_add_normal(menu, CLIENT_RESIZE, _("Resi&ze"), NULL, TRUE);
385 e = menu_add_normal(menu, CLIENT_ICONIFY, _("Ico&nify"), NULL, TRUE);
386 e->data.normal.mask = ob_rr_theme->iconify_mask;
387 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
388 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
389 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
390 e->data.normal.mask_disabled_selected_color =
391 ob_rr_theme->menu_disabled_selected_color;
393 e = menu_add_normal(menu, CLIENT_MAXIMIZE, _("Ma&ximize"), NULL, TRUE);
394 e->data.normal.mask = ob_rr_theme->max_mask;
395 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
396 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
397 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
398 e->data.normal.mask_disabled_selected_color =
399 ob_rr_theme->menu_disabled_selected_color;
401 menu_add_normal(menu, CLIENT_SHADE, _("&Roll up/down"), NULL, TRUE);
403 menu_add_normal(menu, CLIENT_DECORATE, _("Un/&Decorate"), NULL, TRUE);
405 menu_add_separator(menu, -1, NULL);
407 menu_add_submenu(menu, CLIENT_SEND_TO, SEND_TO_MENU_NAME);
409 menu_add_submenu(menu, CLIENT_LAYER, LAYER_MENU_NAME);
411 menu_add_separator(menu, -1, NULL);
413 e = menu_add_normal(menu, CLIENT_CLOSE, _("&Close"), NULL, TRUE);
414 e->data.normal.mask = ob_rr_theme->close_mask;
415 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
416 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
417 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
418 e->data.normal.mask_disabled_selected_color =
419 ob_rr_theme->menu_disabled_selected_color;