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
)
113 if (!config_focus_under_mouse
)
114 ignore_start
= event_start_ignore_all_enters();
118 /* the client won't be on screen anymore so hide the menu */
119 menu_frame_hide_all();
120 f
= NULL
; /* and don't update */
122 client_iconify(c
, TRUE
, FALSE
, FALSE
);
125 client_maximize(c
, FALSE
, 0);
127 case CLIENT_MAXIMIZE
:
128 client_maximize(c
, TRUE
, 0);
131 client_shade(c
, !c
->shaded
);
133 case CLIENT_DECORATE
:
134 client_set_undecorated(c
, !c
->undecorated
);
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 if (!config_focus_under_mouse
)
162 event_end_ignore_all_enters(ignore_start
);
164 /* update the menu cuz stuff can have changed */
166 client_menu_update(f
, NULL
);
167 menu_frame_render(f
);
171 static gboolean
layer_menu_update(ObMenuFrame
*frame
, gpointer data
)
173 ObMenu
*menu
= frame
->menu
;
176 if (frame
->client
== NULL
|| !client_normal(frame
->client
))
177 return FALSE
; /* don't show the menu */
179 for (it
= menu
->entries
; it
; it
= g_list_next(it
)) {
180 ObMenuEntry
*e
= it
->data
;
181 gboolean
*en
= &e
->data
.normal
.enabled
; /* save some typing */
182 ObClient
*c
= frame
->client
;
184 if (e
->type
== OB_MENU_ENTRY_TYPE_NORMAL
) {
187 *en
= !c
->above
&& (c
->functions
& OB_CLIENT_FUNC_ABOVE
);
190 *en
= c
->above
|| c
->below
;
193 *en
= !c
->below
&& (c
->functions
& OB_CLIENT_FUNC_BELOW
);
200 return TRUE
; /* show the menu */
203 static void layer_menu_execute(ObMenuEntry
*e
, ObMenuFrame
*f
,
204 ObClient
*c
, guint state
, gpointer data
)
210 if (!config_focus_under_mouse
)
211 ignore_start
= event_start_ignore_all_enters();
215 client_set_layer(c
, 1);
218 client_set_layer(c
, 0);
221 client_set_layer(c
, -1);
224 g_assert_not_reached();
227 if (!config_focus_under_mouse
)
228 event_end_ignore_all_enters(ignore_start
);
230 /* update the menu cuz stuff can have changed */
232 layer_menu_update(f
, NULL
);
233 menu_frame_render(f
);
237 static gboolean
send_to_menu_update(ObMenuFrame
*frame
, gpointer data
)
239 ObMenu
*menu
= frame
->menu
;
243 menu_clear_entries(menu
);
245 if (frame
->client
== NULL
|| !client_normal(frame
->client
))
246 return FALSE
; /* don't show the menu */
248 for (i
= 0; i
<= screen_num_desktops
; ++i
) {
252 if (i
>= screen_num_desktops
) {
253 menu_add_separator(menu
, -1, NULL
);
256 name
= _("All desktops");
259 name
= screen_desktop_names
[i
];
262 e
= menu_add_normal(menu
, desk
, name
, NULL
, FALSE
);
264 if (desk
== DESKTOP_ALL
) {
265 e
->data
.normal
.mask
= ob_rr_theme
->desk_mask
;
266 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
267 e
->data
.normal
.mask_selected_color
=
268 ob_rr_theme
->menu_selected_color
;
269 e
->data
.normal
.mask_disabled_color
=
270 ob_rr_theme
->menu_disabled_color
;
271 e
->data
.normal
.mask_disabled_selected_color
=
272 ob_rr_theme
->menu_disabled_selected_color
;
275 if (frame
->client
->desktop
== desk
)
276 e
->data
.normal
.enabled
= FALSE
;
278 return TRUE
; /* show the menu */
281 static void send_to_menu_execute(ObMenuEntry
*e
, ObMenuFrame
*f
,
282 ObClient
*c
, guint state
, gpointer data
)
286 client_set_desktop(c
, e
->id
, FALSE
, FALSE
);
287 /* the client won't even be on the screen anymore, so hide the menu */
289 menu_frame_hide_all();
292 static void client_menu_place(ObMenuFrame
*frame
, gint
*x
, gint
*y
,
293 gboolean mouse
, gpointer data
)
297 if (!mouse
&& frame
->client
) {
298 *x
= frame
->client
->frame
->area
.x
;
300 /* try below the titlebar */
301 *y
= frame
->client
->frame
->area
.y
+ frame
->client
->frame
->size
.top
-
302 frame
->client
->frame
->bwidth
;
303 menu_frame_move_on_screen(frame
, *x
, *y
, &dx
, &dy
);
305 /* try above the titlebar */
306 *y
= frame
->client
->frame
->area
.y
+ frame
->client
->frame
->bwidth
-
308 menu_frame_move_on_screen(frame
, *x
, *y
, &dx
, &dy
);
311 /* didnt fit either way, use move on screen's values */
312 *y
= frame
->client
->frame
->area
.y
+ frame
->client
->frame
->size
.top
;
313 menu_frame_move_on_screen(frame
, *x
, *y
, &dx
, &dy
);
324 /* try to the bottom right of the cursor */
325 menu_frame_move_on_screen(frame
, myx
, myy
, &dx
, &dy
);
326 if (dx
!= 0 || dy
!= 0) {
327 /* try to the bottom left of the cursor */
328 myx
= *x
- frame
->area
.width
;
330 menu_frame_move_on_screen(frame
, myx
, myy
, &dx
, &dy
);
332 if (dx
!= 0 || dy
!= 0) {
333 /* try to the top right of the cursor */
335 myy
= *y
- frame
->area
.height
;
336 menu_frame_move_on_screen(frame
, myx
, myy
, &dx
, &dy
);
338 if (dx
!= 0 || dy
!= 0) {
339 /* try to the top left of the cursor */
340 myx
= *x
- frame
->area
.width
;
341 myy
= *y
- frame
->area
.height
;
342 menu_frame_move_on_screen(frame
, myx
, myy
, &dx
, &dy
);
344 if (dx
!= 0 || dy
!= 0) {
345 /* if didnt fit on either side so just use what it says */
348 menu_frame_move_on_screen(frame
, myx
, myy
, &dx
, &dy
);
355 void client_menu_startup()
360 menu
= menu_new(LAYER_MENU_NAME
, _("_Layer"), TRUE
, NULL
);
361 menu_show_all_shortcuts(menu
, TRUE
);
362 menu_set_update_func(menu
, layer_menu_update
);
363 menu_set_execute_func(menu
, layer_menu_execute
);
365 menu_add_normal(menu
, LAYER_TOP
, _("Always on _top"), NULL
, TRUE
);
366 menu_add_normal(menu
, LAYER_NORMAL
, _("_Normal"), NULL
, TRUE
);
367 menu_add_normal(menu
, LAYER_BOTTOM
, _("Always on _bottom"),NULL
, TRUE
);
370 menu
= menu_new(SEND_TO_MENU_NAME
, _("_Send to desktop"), TRUE
, NULL
);
371 menu_set_update_func(menu
, send_to_menu_update
);
372 menu_set_execute_func(menu
, send_to_menu_execute
);
374 menu
= menu_new(CLIENT_MENU_NAME
, _("Client menu"), TRUE
, NULL
);
375 menu_show_all_shortcuts(menu
, TRUE
);
376 menu_set_update_func(menu
, client_menu_update
);
377 menu_set_place_func(menu
, client_menu_place
);
378 menu_set_execute_func(menu
, client_menu_execute
);
380 e
= menu_add_normal(menu
, CLIENT_RESTORE
, _("R_estore"), NULL
, TRUE
);
381 e
->data
.normal
.mask
= ob_rr_theme
->max_toggled_mask
;
382 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
383 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
384 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
385 e
->data
.normal
.mask_disabled_selected_color
=
386 ob_rr_theme
->menu_disabled_selected_color
;
388 menu_add_normal(menu
, CLIENT_MOVE
, _("_Move"), NULL
, TRUE
);
390 menu_add_normal(menu
, CLIENT_RESIZE
, _("Resi_ze"), NULL
, TRUE
);
392 e
= menu_add_normal(menu
, CLIENT_ICONIFY
, _("Ico_nify"), NULL
, TRUE
);
393 e
->data
.normal
.mask
= ob_rr_theme
->iconify_mask
;
394 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
395 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
396 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
397 e
->data
.normal
.mask_disabled_selected_color
=
398 ob_rr_theme
->menu_disabled_selected_color
;
400 e
= menu_add_normal(menu
, CLIENT_MAXIMIZE
, _("Ma_ximize"), NULL
, TRUE
);
401 e
->data
.normal
.mask
= ob_rr_theme
->max_mask
;
402 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
403 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
404 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
405 e
->data
.normal
.mask_disabled_selected_color
=
406 ob_rr_theme
->menu_disabled_selected_color
;
408 menu_add_normal(menu
, CLIENT_SHADE
, _("_Roll up/down"), NULL
, TRUE
);
410 menu_add_normal(menu
, CLIENT_DECORATE
, _("Un/_Decorate"), NULL
, TRUE
);
412 menu_add_separator(menu
, -1, NULL
);
414 menu_add_submenu(menu
, CLIENT_SEND_TO
, SEND_TO_MENU_NAME
);
416 menu_add_submenu(menu
, CLIENT_LAYER
, LAYER_MENU_NAME
);
418 menu_add_separator(menu
, -1, NULL
);
420 e
= menu_add_normal(menu
, CLIENT_CLOSE
, _("_Close"), NULL
, TRUE
);
421 e
->data
.normal
.mask
= ob_rr_theme
->close_mask
;
422 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
423 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
424 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
425 e
->data
.normal
.mask_disabled_selected_color
=
426 ob_rr_theme
->menu_disabled_selected_color
;