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);
123 case CLIENT_MAXIMIZE:
124 client_maximize(c, TRUE, 0);
127 client_shade(c, !c->shaded);
129 case CLIENT_DECORATE:
130 client_set_undecorated(c, !c->undecorated);
133 /* this needs to grab the keyboard so hide the menu */
134 menu_frame_hide_all();
135 f = NULL; /* and don't update */
137 screen_pointer_pos(&x, &y);
138 moveresize_start(c, x, y, 0,
139 prop_atoms.net_wm_moveresize_move_keyboard);
142 /* this needs to grab the keyboard so hide the menu */
143 menu_frame_hide_all();
144 f = NULL; /* and don't update */
146 screen_pointer_pos(&x, &y);
147 moveresize_start(c, x, y, 0,
148 prop_atoms.net_wm_moveresize_size_keyboard);
154 g_assert_not_reached();
157 event_ignore_all_queued_enters();
159 /* update the menu cuz stuff can have changed */
161 client_menu_update(f, NULL);
162 menu_frame_render(f);
166 static gboolean layer_menu_update(ObMenuFrame *frame, gpointer data)
168 ObMenu *menu = frame->menu;
171 if (frame->client == NULL || !client_normal(frame->client))
172 return FALSE; /* don't show the menu */
174 for (it = menu->entries; it; it = g_list_next(it)) {
175 ObMenuEntry *e = it->data;
176 gboolean *en = &e->data.normal.enabled; /* save some typing */
177 ObClient *c = frame->client;
179 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL) {
182 *en = !c->above && (c->functions & OB_CLIENT_FUNC_ABOVE);
185 *en = c->above || c->below;
188 *en = !c->below && (c->functions & OB_CLIENT_FUNC_BELOW);
195 return TRUE; /* show the menu */
198 static void layer_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
199 ObClient *c, guint state, gpointer data,
206 client_set_layer(c, 1);
209 client_set_layer(c, 0);
212 client_set_layer(c, -1);
215 g_assert_not_reached();
218 event_ignore_all_queued_enters();
220 /* update the menu cuz stuff can have changed */
222 layer_menu_update(f, NULL);
223 menu_frame_render(f);
227 static gboolean send_to_menu_update(ObMenuFrame *frame, gpointer data)
229 ObMenu *menu = frame->menu;
233 menu_clear_entries(menu);
235 if (frame->client == NULL || !client_normal(frame->client))
236 return FALSE; /* don't show the menu */
238 for (i = 0; i <= screen_num_desktops; ++i) {
242 if (i >= screen_num_desktops) {
243 menu_add_separator(menu, -1, NULL);
246 name = _("All desktops");
249 name = screen_desktop_names[i];
252 e = menu_add_normal(menu, desk, name, NULL, FALSE);
254 if (desk == DESKTOP_ALL) {
255 e->data.normal.mask = ob_rr_theme->desk_mask;
256 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
257 e->data.normal.mask_selected_color =
258 ob_rr_theme->menu_selected_color;
259 e->data.normal.mask_disabled_color =
260 ob_rr_theme->menu_disabled_color;
261 e->data.normal.mask_disabled_selected_color =
262 ob_rr_theme->menu_disabled_selected_color;
265 if (frame->client->desktop == desk)
266 e->data.normal.enabled = FALSE;
268 return TRUE; /* show the menu */
271 static void send_to_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
272 ObClient *c, guint state, gpointer data,
277 client_set_desktop(c, e->id, FALSE);
278 /* the client won't even be on the screen anymore, so hide the menu */
280 menu_frame_hide_all();
283 static void client_menu_place(ObMenuFrame *frame, gint *x, gint *y,
284 gint button, gpointer data)
288 if (button == 0 && frame->client) {
289 *x = frame->client->frame->area.x;
291 /* try below the titlebar */
292 *y = frame->client->frame->area.y + frame->client->frame->size.top -
293 frame->client->frame->bwidth;
294 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
296 /* try above the titlebar */
297 *y = frame->client->frame->area.y + frame->client->frame->bwidth -
299 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
302 /* didnt fit either way, use move on screen's values */
303 *y = frame->client->frame->area.y + frame->client->frame->size.top;
304 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
315 /* try to the bottom right of the cursor */
316 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
317 if (dx != 0 || dy != 0) {
318 /* try to the bottom left of the cursor */
319 myx = *x - frame->area.width;
321 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
323 if (dx != 0 || dy != 0) {
324 /* try to the top right of the cursor */
326 myy = *y - frame->area.height;
327 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
329 if (dx != 0 || dy != 0) {
330 /* try to the top left of the cursor */
331 myx = *x - frame->area.width;
332 myy = *y - frame->area.height;
333 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
335 if (dx != 0 || dy != 0) {
336 /* if didnt fit on either side so just use what it says */
339 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
346 void client_menu_startup()
351 menu = menu_new(LAYER_MENU_NAME, _("&Layer"), TRUE, NULL);
352 menu_show_all_shortcuts(menu, TRUE);
353 menu_set_update_func(menu, layer_menu_update);
354 menu_set_execute_func(menu, layer_menu_execute);
356 menu_add_normal(menu, LAYER_TOP, _("Always on &top"), NULL, TRUE);
357 menu_add_normal(menu, LAYER_NORMAL, _("&Normal"), NULL, TRUE);
358 menu_add_normal(menu, LAYER_BOTTOM, _("Always on &bottom"),NULL, TRUE);
361 menu = menu_new(SEND_TO_MENU_NAME, _("&Send to desktop"), TRUE, NULL);
362 menu_set_update_func(menu, send_to_menu_update);
363 menu_set_execute_func(menu, send_to_menu_execute);
365 menu = menu_new(CLIENT_MENU_NAME, _("Client menu"), TRUE, NULL);
366 menu_show_all_shortcuts(menu, TRUE);
367 menu_set_update_func(menu, client_menu_update);
368 menu_set_place_func(menu, client_menu_place);
369 menu_set_execute_func(menu, client_menu_execute);
371 e = menu_add_normal(menu, CLIENT_RESTORE, _("R&estore"), NULL, TRUE);
372 e->data.normal.mask = ob_rr_theme->max_toggled_mask;
373 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
374 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
375 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
376 e->data.normal.mask_disabled_selected_color =
377 ob_rr_theme->menu_disabled_selected_color;
379 menu_add_normal(menu, CLIENT_MOVE, _("&Move"), NULL, TRUE);
381 menu_add_normal(menu, CLIENT_RESIZE, _("Resi&ze"), NULL, TRUE);
383 e = menu_add_normal(menu, CLIENT_ICONIFY, _("Ico&nify"), NULL, TRUE);
384 e->data.normal.mask = ob_rr_theme->iconify_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 e = menu_add_normal(menu, CLIENT_MAXIMIZE, _("Ma&ximize"), NULL, TRUE);
392 e->data.normal.mask = ob_rr_theme->max_mask;
393 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
394 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
395 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
396 e->data.normal.mask_disabled_selected_color =
397 ob_rr_theme->menu_disabled_selected_color;
399 menu_add_normal(menu, CLIENT_SHADE, _("&Roll up/down"), NULL, TRUE);
401 menu_add_normal(menu, CLIENT_DECORATE, _("Un/&Decorate"), NULL, TRUE);
403 menu_add_separator(menu, -1, NULL);
405 menu_add_submenu(menu, CLIENT_SEND_TO, SEND_TO_MENU_NAME);
407 menu_add_submenu(menu, CLIENT_LAYER, LAYER_MENU_NAME);
409 menu_add_separator(menu, -1, NULL);
411 e = menu_add_normal(menu, CLIENT_CLOSE, _("&Close"), NULL, TRUE);
412 e->data.normal.mask = ob_rr_theme->close_mask;
413 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
414 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
415 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
416 e->data.normal.mask_disabled_selected_color =
417 ob_rr_theme->menu_disabled_selected_color;