]> Dogcows Code - chaz/openbox/blob - openbox/client_menu.c
separate roll up and roll down.
[chaz/openbox] / openbox / client_menu.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3 client_menu.c for the Openbox window manager
4 Copyright (c) 2003-2007 Dana Jansens
5
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.
10
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.
15
16 See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include "debug.h"
20 #include "menu.h"
21 #include "menuframe.h"
22 #include "screen.h"
23 #include "client.h"
24 #include "openbox.h"
25 #include "frame.h"
26 #include "moveresize.h"
27 #include "prop.h"
28 #include "gettext.h"
29
30 #include <glib.h>
31
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"
35
36 enum {
37 LAYER_TOP,
38 LAYER_NORMAL,
39 LAYER_BOTTOM
40 };
41
42 enum {
43 CLIENT_SEND_TO,
44 CLIENT_LAYER,
45 CLIENT_ICONIFY,
46 CLIENT_RESTORE,
47 CLIENT_MAXIMIZE,
48 CLIENT_ROLL_UP,
49 CLIENT_ROLL_DOWN,
50 CLIENT_DECORATE,
51 CLIENT_MOVE,
52 CLIENT_RESIZE,
53 CLIENT_CLOSE
54 };
55
56 static gboolean client_menu_update(ObMenuFrame *frame, gpointer data)
57 {
58 ObMenu *menu = frame->menu;
59 GList *it;
60
61 if (frame->client == NULL || !client_normal(frame->client))
62 return FALSE; /* don't show the menu */
63
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;
68
69 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL) {
70 switch (e->id) {
71 case CLIENT_ICONIFY:
72 *en = c->functions & OB_CLIENT_FUNC_ICONIFY;
73 break;
74 case CLIENT_RESTORE:
75 *en = c->max_horz || c->max_vert;
76 break;
77 case CLIENT_MAXIMIZE:
78 *en = ((c->functions & OB_CLIENT_FUNC_MAXIMIZE) &&
79 (!c->max_horz || !c->max_vert));
80 break;
81 case CLIENT_ROLL_UP:
82 *en = c->functions & OB_CLIENT_FUNC_SHADE && !c->shaded;
83 break;
84 case CLIENT_ROLL_DOWN:
85 *en = c->functions & OB_CLIENT_FUNC_SHADE && c->shaded;
86 break;
87 case CLIENT_MOVE:
88 *en = c->functions & OB_CLIENT_FUNC_MOVE;
89 break;
90 case CLIENT_RESIZE:
91 *en = c->functions & OB_CLIENT_FUNC_RESIZE;
92 break;
93 case CLIENT_CLOSE:
94 *en = c->functions & OB_CLIENT_FUNC_CLOSE;
95 break;
96 case CLIENT_DECORATE:
97 *en = client_normal(c);
98 break;
99 default:
100 *en = TRUE;
101 }
102 }
103 }
104 return TRUE; /* show the menu */
105 }
106
107 static void client_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
108 ObClient *c, guint state, gpointer data,
109 Time time)
110 {
111 gint x, y;
112
113 g_assert(c);
114
115 switch (e->id) {
116 case CLIENT_ICONIFY:
117 /* the client won't be on screen anymore so hide the menu */
118 menu_frame_hide_all();
119 f = NULL; /* and don't update */
120
121 client_iconify(c, TRUE, FALSE, FALSE);
122 break;
123 case CLIENT_RESTORE:
124 client_maximize(c, FALSE, 0);
125 break;
126 case CLIENT_MAXIMIZE:
127 client_maximize(c, TRUE, 0);
128 break;
129 case CLIENT_ROLL_UP:
130 client_shade(c, TRUE);
131 break;
132 case CLIENT_ROLL_DOWN:
133 client_shade(c, FALSE);
134 break;
135 case CLIENT_DECORATE:
136 client_set_undecorated(c, !c->undecorated);
137 break;
138 case CLIENT_MOVE:
139 /* this needs to grab the keyboard so hide the menu */
140 menu_frame_hide_all();
141 f = NULL; /* and don't update */
142
143 screen_pointer_pos(&x, &y);
144 moveresize_start(c, x, y, 0,
145 prop_atoms.net_wm_moveresize_move_keyboard);
146 break;
147 case CLIENT_RESIZE:
148 /* this needs to grab the keyboard so hide the menu */
149 menu_frame_hide_all();
150 f = NULL; /* and don't update */
151
152 screen_pointer_pos(&x, &y);
153 moveresize_start(c, x, y, 0,
154 prop_atoms.net_wm_moveresize_size_keyboard);
155 break;
156 case CLIENT_CLOSE:
157 client_close(c);
158 break;
159 default:
160 g_assert_not_reached();
161 }
162
163 /* update the menu cuz stuff can have changed */
164 if (f) {
165 client_menu_update(f, NULL);
166 menu_frame_render(f);
167 }
168 }
169
170 static gboolean layer_menu_update(ObMenuFrame *frame, gpointer data)
171 {
172 ObMenu *menu = frame->menu;
173 GList *it;
174
175 if (frame->client == NULL || !client_normal(frame->client))
176 return FALSE; /* don't show the menu */
177
178 for (it = menu->entries; it; it = g_list_next(it)) {
179 ObMenuEntry *e = it->data;
180 gboolean *en = &e->data.normal.enabled; /* save some typing */
181 ObClient *c = frame->client;
182
183 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL) {
184 switch (e->id) {
185 case LAYER_TOP:
186 *en = !c->above;
187 break;
188 case LAYER_NORMAL:
189 *en = c->above || c->below;
190 break;
191 case LAYER_BOTTOM:
192 *en = !c->below;
193 break;
194 default:
195 *en = TRUE;
196 }
197 }
198 }
199 return TRUE; /* show the menu */
200 }
201
202 static void layer_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
203 ObClient *c, guint state, gpointer data,
204 Time time)
205 {
206 g_assert(c);
207
208 switch (e->id) {
209 case LAYER_TOP:
210 client_set_layer(c, 1);
211 break;
212 case LAYER_NORMAL:
213 client_set_layer(c, 0);
214 break;
215 case LAYER_BOTTOM:
216 client_set_layer(c, -1);
217 break;
218 default:
219 g_assert_not_reached();
220 }
221
222 /* update the menu cuz stuff can have changed */
223 if (f) {
224 layer_menu_update(f, NULL);
225 menu_frame_render(f);
226 }
227 }
228
229 static gboolean send_to_menu_update(ObMenuFrame *frame, gpointer data)
230 {
231 ObMenu *menu = frame->menu;
232 guint i;
233 ObMenuEntry *e;
234
235 menu_clear_entries(menu);
236
237 if (frame->client == NULL || !client_normal(frame->client))
238 return FALSE; /* don't show the menu */
239
240 for (i = 0; i <= screen_num_desktops; ++i) {
241 const gchar *name;
242 guint desk;
243
244 if (i >= screen_num_desktops) {
245 menu_add_separator(menu, -1, NULL);
246
247 desk = DESKTOP_ALL;
248 name = _("All desktops");
249 } else {
250 desk = i;
251 name = screen_desktop_names[i];
252 }
253
254 e = menu_add_normal(menu, desk, name, NULL, FALSE);
255 e->id = desk;
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;
265 }
266
267 if (frame->client->desktop == desk)
268 e->data.normal.enabled = FALSE;
269 }
270 return TRUE; /* show the menu */
271 }
272
273 static void send_to_menu_execute(ObMenuEntry *e, ObMenuFrame *f,
274 ObClient *c, guint state, gpointer data,
275 Time time)
276 {
277 g_assert(c);
278
279 client_set_desktop(c, e->id, FALSE);
280 /* the client won't even be on the screen anymore, so hide the menu */
281 if (f)
282 menu_frame_hide_all();
283 }
284
285 static void client_menu_place(ObMenuFrame *frame, gint *x, gint *y,
286 gint button, gpointer data)
287 {
288 gint dx, dy;
289
290 if (button == 0 && frame->client) {
291 *x = frame->client->frame->area.x;
292
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);
297 if (dy != 0) {
298 /* try above the titlebar */
299 *y = frame->client->frame->area.y + frame->client->frame->bwidth -
300 frame->area.height;
301 menu_frame_move_on_screen(frame, *x, *y, &dx, &dy);
302 }
303 if (dy != 0) {
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);
307 }
308
309 *x += dx;
310 *y += dy;
311 } else {
312 gint myx, myy;
313
314 myx = *x;
315 myy = *y;
316
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;
322 myy = *y;
323 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
324 }
325 if (dx != 0 || dy != 0) {
326 /* try to the top right of the cursor */
327 myx = *x;
328 myy = *y - frame->area.height;
329 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
330 }
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);
336 }
337 if (dx != 0 || dy != 0) {
338 /* if didnt fit on either side so just use what it says */
339 myx = *x;
340 myy = *y;
341 menu_frame_move_on_screen(frame, myx, myy, &dx, &dy);
342 }
343 *x = myx + dx;
344 *y = myy + dy;
345 }
346 }
347
348 void client_menu_startup()
349 {
350 ObMenu *menu;
351 ObMenuEntry *e;
352
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);
357
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);
361
362
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);
366
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);
372
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;
380
381 menu_add_normal(menu, CLIENT_MOVE, _("&Move"), NULL, TRUE);
382
383 menu_add_normal(menu, CLIENT_RESIZE, _("Resi&ze"), NULL, TRUE);
384
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;
392
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;
400
401 menu_add_normal(menu, CLIENT_ROLL_UP, _("Roll &up"), NULL, TRUE);
402
403 menu_add_normal(menu, CLIENT_ROLL_DOWN, _("Roll do&wn"), NULL, TRUE);
404
405 menu_add_normal(menu, CLIENT_DECORATE, _("Un/&Decorate"), NULL, TRUE);
406
407 menu_add_separator(menu, -1, NULL);
408
409 menu_add_submenu(menu, CLIENT_SEND_TO, SEND_TO_MENU_NAME);
410
411 menu_add_submenu(menu, CLIENT_LAYER, LAYER_MENU_NAME);
412
413 menu_add_separator(menu, -1, NULL);
414
415 e = menu_add_normal(menu, CLIENT_CLOSE, _("&Close"), NULL, TRUE);
416 e->data.normal.mask = ob_rr_theme->close_mask;
417 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
418 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
419 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
420 e->data.normal.mask_disabled_selected_color =
421 ob_rr_theme->menu_disabled_selected_color;
422 }
This page took 0.057485 seconds and 5 git commands to generate.