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"
27 #include "moveresize.h"
34 #define CLIENT_MENU_NAME "client-menu"
35 #define SEND_TO_MENU_NAME "client-send-to-menu"
36 #define LAYER_MENU_NAME "client-layer-menu"
57 static gboolean client_menu_update(ObMenuFrame *frame, gpointer data)
59 ObMenu *menu = frame->menu;
62 if (frame->client == NULL || !client_normal(frame->client))
63 return FALSE; /* don't show the menu */
65 for (it = menu->entries; it; it = g_list_next(it)) {
66 ObMenuEntry *e = it->data;
67 gboolean *en = &e->data.normal.enabled; /* save some typing */
68 ObClient *c = frame->client;
70 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL) {
73 *en = c->functions & OB_CLIENT_FUNC_ICONIFY;
76 *en = c->max_horz || c->max_vert;
79 *en = ((c->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
80 (!c->max_horz || !c->max_vert));
83 *en = c->functions & OB_CLIENT_FUNC_SHADE;
86 *en = c->functions & OB_CLIENT_FUNC_MOVE;
89 *en = c->functions & OB_CLIENT_FUNC_RESIZE;
92 *en = c->functions & OB_CLIENT_FUNC_CLOSE;
95 *en = c->functions & OB_CLIENT_FUNC_UNDECORATE;
102 return TRUE; /* show the menu */
105 static void client_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
106 ObClient *c, guint state, gpointer data,
114 if (!config_focus_under_mouse)
115 ignore_start = event_start_ignore_all_enters();
119 /* the client won't be on screen anymore so hide the menu */
120 menu_frame_hide_all();
121 f = NULL; /* and don't update */
123 client_iconify(c, TRUE, FALSE, FALSE);
126 client_maximize(c, FALSE, 0);
128 case CLIENT_MAXIMIZE:
129 client_maximize(c, TRUE, 0);
132 client_shade(c, !c->shaded);
134 case CLIENT_DECORATE:
135 client_set_undecorated(c, !c->undecorated);
138 /* this needs to grab the keyboard so hide the menu */
139 menu_frame_hide_all();
140 f = NULL; /* and don't update */
142 screen_pointer_pos(&x, &y);
143 moveresize_start(c, x, y, 0,
144 prop_atoms.net_wm_moveresize_move_keyboard);
147 /* this needs to grab the keyboard so hide the menu */
148 menu_frame_hide_all();
149 f = NULL; /* and don't update */
151 screen_pointer_pos(&x, &y);
152 moveresize_start(c, x, y, 0,
153 prop_atoms.net_wm_moveresize_size_keyboard);
159 g_assert_not_reached();
162 if (!config_focus_under_mouse)
163 event_end_ignore_all_enters(ignore_start);
165 /* update the menu cuz stuff can have changed */
167 client_menu_update(f, NULL);
168 menu_frame_render(f);
172 static gboolean layer_menu_update(ObMenuFrame *frame, gpointer data)
174 ObMenu *menu = frame->menu;
177 if (frame->client == NULL || !client_normal(frame->client))
178 return FALSE; /* don't show the menu */
180 for (it = menu->entries; it; it = g_list_next(it)) {
181 ObMenuEntry *e = it->data;
182 gboolean *en = &e->data.normal.enabled; /* save some typing */
183 ObClient *c = frame->client;
185 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL) {
188 *en = !c->above && (c->functions & OB_CLIENT_FUNC_ABOVE);
191 *en = c->above || c->below;
194 *en = !c->below && (c->functions & OB_CLIENT_FUNC_BELOW);
201 return TRUE; /* show the menu */
204 static void layer_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
205 ObClient *c, guint state, gpointer data,
212 if (!config_focus_under_mouse)
213 ignore_start = event_start_ignore_all_enters();
217 client_set_layer(c, 1);
220 client_set_layer(c, 0);
223 client_set_layer(c, -1);
226 g_assert_not_reached();
229 if (!config_focus_under_mouse)
230 event_end_ignore_all_enters(ignore_start);
232 /* update the menu cuz stuff can have changed */
234 layer_menu_update(f, NULL);
235 menu_frame_render(f);
239 static gboolean send_to_menu_update(ObMenuFrame *frame, gpointer data)
241 ObMenu *menu = frame->menu;
245 menu_clear_entries(menu);
247 if (frame->client == NULL || !client_normal(frame->client))
248 return FALSE; /* don't show the menu */
250 for (i = 0; i <= screen_num_desktops; ++i) {
254 if (i >= screen_num_desktops) {
255 menu_add_separator(menu, -1, NULL);
258 name = _("All desktops");
261 name = screen_desktop_names[i];
264 e = menu_add_normal(menu, desk, name, NULL, FALSE);
266 if (desk == DESKTOP_ALL) {
267 e->data.normal.mask = ob_rr_theme->desk_mask;
268 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
269 e->data.normal.mask_selected_color =
270 ob_rr_theme->menu_selected_color;
271 e->data.normal.mask_disabled_color =
272 ob_rr_theme->menu_disabled_color;
273 e->data.normal.mask_disabled_selected_color =
274 ob_rr_theme->menu_disabled_selected_color;
277 if (frame->client->desktop == desk)
278 e->data.normal.enabled = FALSE;
280 return TRUE; /* show the menu */
283 static void send_to_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
284 ObClient *c, guint state, gpointer data,
289 client_set_desktop(c, e->id, FALSE);
290 /* the client won't even be on the screen anymore, so hide the menu */
292 menu_frame_hide_all();
295 static void client_menu_place(ObMenuFrame *frame, gint *x, gint *y,
296 gint button, gpointer data)
300 if (button == 0 && frame->client) {
301 *x = frame->client->frame->area.x;
303 /* try below the titlebar */
304 *y = frame->client->frame->area.y + frame->client->frame->size.top -
305 frame->client->frame->bwidth;
306 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
308 /* try above the titlebar */
309 *y = frame->client->frame->area.y + frame->client->frame->bwidth -
311 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
314 /* didnt fit either way, use move on screen's values */
315 *y = frame->client->frame->area.y + frame->client->frame->size.top;
316 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
327 /* try to the bottom right of the cursor */
328 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
329 if (dx != 0 || dy != 0) {
330 /* try to the bottom left of the cursor */
331 myx = *x - frame->area.width;
333 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
335 if (dx != 0 || dy != 0) {
336 /* try to the top right of the cursor */
338 myy = *y - frame->area.height;
339 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
341 if (dx != 0 || dy != 0) {
342 /* try to the top left of the cursor */
343 myx = *x - frame->area.width;
344 myy = *y - frame->area.height;
345 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
347 if (dx != 0 || dy != 0) {
348 /* if didnt fit on either side so just use what it says */
351 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
358 void client_menu_startup()
363 menu = menu_new(LAYER_MENU_NAME, _("&Layer"), TRUE, NULL);
364 menu_show_all_shortcuts(menu, TRUE);
365 menu_set_update_func(menu, layer_menu_update);
366 menu_set_execute_func(menu, layer_menu_execute);
368 menu_add_normal(menu, LAYER_TOP, _("Always on &top"), NULL, TRUE);
369 menu_add_normal(menu, LAYER_NORMAL, _("&Normal"), NULL, TRUE);
370 menu_add_normal(menu, LAYER_BOTTOM, _("Always on &bottom"),NULL, TRUE);
373 menu = menu_new(SEND_TO_MENU_NAME, _("&Send to desktop"), TRUE, NULL);
374 menu_set_update_func(menu, send_to_menu_update);
375 menu_set_execute_func(menu, send_to_menu_execute);
377 menu = menu_new(CLIENT_MENU_NAME, _("Client menu"), TRUE, NULL);
378 menu_show_all_shortcuts(menu, TRUE);
379 menu_set_update_func(menu, client_menu_update);
380 menu_set_place_func(menu, client_menu_place);
381 menu_set_execute_func(menu, client_menu_execute);
383 e = menu_add_normal(menu, CLIENT_RESTORE, _("R&estore"), NULL, TRUE);
384 e->data.normal.mask = ob_rr_theme->max_toggled_mask;
385 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
386 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
387 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
388 e->data.normal.mask_disabled_selected_color =
389 ob_rr_theme->menu_disabled_selected_color;
391 menu_add_normal(menu, CLIENT_MOVE, _("&Move"), NULL, TRUE);
393 menu_add_normal(menu, CLIENT_RESIZE, _("Resi&ze"), NULL, TRUE);
395 e = menu_add_normal(menu, CLIENT_ICONIFY, _("Ico&nify"), NULL, TRUE);
396 e->data.normal.mask = ob_rr_theme->iconify_mask;
397 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
398 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
399 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
400 e->data.normal.mask_disabled_selected_color =
401 ob_rr_theme->menu_disabled_selected_color;
403 e = menu_add_normal(menu, CLIENT_MAXIMIZE, _("Ma&ximize"), NULL, TRUE);
404 e->data.normal.mask = ob_rr_theme->max_mask;
405 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
406 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
407 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
408 e->data.normal.mask_disabled_selected_color =
409 ob_rr_theme->menu_disabled_selected_color;
411 menu_add_normal(menu, CLIENT_SHADE, _("&Roll up/down"), NULL, TRUE);
413 menu_add_normal(menu, CLIENT_DECORATE, _("Un/&Decorate"), NULL, TRUE);
415 menu_add_separator(menu, -1, NULL);
417 menu_add_submenu(menu, CLIENT_SEND_TO, SEND_TO_MENU_NAME);
419 menu_add_submenu(menu, CLIENT_LAYER, LAYER_MENU_NAME);
421 menu_add_separator(menu, -1, NULL);
423 e = menu_add_normal(menu, CLIENT_CLOSE, _("&Close"), NULL, TRUE);
424 e->data.normal.mask = ob_rr_theme->close_mask;
425 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
426 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
427 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
428 e->data.normal.mask_disabled_selected_color =
429 ob_rr_theme->menu_disabled_selected_color;