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"
30 #define CLIENT_MENU_NAME "client-menu"
31 #define SEND_TO_MENU_NAME "client-send-to-menu"
32 #define LAYER_MENU_NAME "client-layer-menu"
53 static gboolean
client_update(ObMenuFrame
*frame
, gpointer data
)
55 ObMenu
*menu
= frame
->menu
;
59 if (frame
->client
== NULL
|| !client_normal(frame
->client
))
60 return FALSE
; /* don't show the menu */
62 for (it
= menu
->entries
; it
; it
= g_list_next(it
)) {
64 if (e
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
65 e
->data
.normal
.enabled
= TRUE
;
68 e
= menu_find_entry_id(menu
, CLIENT_ICONIFY
);
69 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_ICONIFY
;
71 e
= menu_find_entry_id(menu
, CLIENT_RESTORE
);
72 e
->data
.normal
.enabled
=frame
->client
->max_horz
|| frame
->client
->max_vert
;
74 e
= menu_find_entry_id(menu
, CLIENT_MAXIMIZE
);
75 e
->data
.normal
.enabled
=
76 (frame
->client
->functions
& OB_CLIENT_FUNC_MAXIMIZE
) &&
77 !frame
->client
->max_horz
&& !frame
->client
->max_vert
;
79 e
= menu_find_entry_id(menu
, CLIENT_SHADE
);
80 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_SHADE
;
82 e
= menu_find_entry_id(menu
, CLIENT_MOVE
);
83 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_MOVE
;
85 e
= menu_find_entry_id(menu
, CLIENT_RESIZE
);
86 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_RESIZE
;
88 e
= menu_find_entry_id(menu
, CLIENT_CLOSE
);
89 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_CLOSE
;
91 e
= menu_find_entry_id(menu
, CLIENT_DECORATE
);
92 e
->data
.normal
.enabled
= client_normal(frame
->client
);
93 return TRUE
; /* show the menu */
96 static gboolean
layer_update(ObMenuFrame
*frame
, gpointer data
)
98 ObMenu
*menu
= frame
->menu
;
102 if (frame
->client
== NULL
|| !client_normal(frame
->client
))
103 return FALSE
; /* don't show the menu */
105 for (it
= menu
->entries
; it
; it
= g_list_next(it
)) {
107 if (e
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
108 e
->data
.normal
.enabled
= TRUE
;
111 e
= menu_find_entry_id(menu
, LAYER_TOP
);
112 e
->data
.normal
.enabled
= !frame
->client
->above
;
114 e
= menu_find_entry_id(menu
, LAYER_NORMAL
);
115 e
->data
.normal
.enabled
= (frame
->client
->above
|| frame
->client
->below
);
117 e
= menu_find_entry_id(menu
, LAYER_BOTTOM
);
118 e
->data
.normal
.enabled
= !frame
->client
->below
;
119 return TRUE
; /* show the menu */
122 static gboolean
send_to_update(ObMenuFrame
*frame
, gpointer data
)
124 ObMenu
*menu
= frame
->menu
;
130 menu_clear_entries(menu
);
132 if (frame
->client
== NULL
|| !client_normal(frame
->client
))
133 return FALSE
; /* don't show the menu */
135 for (i
= 0; i
<= screen_num_desktops
; ++i
) {
139 if (i
>= screen_num_desktops
) {
140 menu_add_separator(menu
, -1, NULL
);
143 name
= _("All desktops");
146 name
= screen_desktop_names
[i
];
149 act
= action_from_string("SendToDesktop",
150 OB_USER_ACTION_MENU_SELECTION
);
151 act
->data
.sendto
.desk
= desk
;
152 act
->data
.sendto
.follow
= FALSE
;
153 acts
= g_slist_prepend(NULL
, act
);
154 e
= menu_add_normal(menu
, desk
, name
, acts
, FALSE
);
155 if (desk
== DESKTOP_ALL
) {
156 e
->data
.normal
.mask
= ob_rr_theme
->desk_mask
;
157 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
158 e
->data
.normal
.mask_selected_color
=
159 ob_rr_theme
->menu_selected_color
;
160 e
->data
.normal
.mask_disabled_color
=
161 ob_rr_theme
->menu_disabled_color
;
162 e
->data
.normal
.mask_disabled_selected_color
=
163 ob_rr_theme
->menu_disabled_selected_color
;
166 if (frame
->client
->desktop
== desk
)
167 e
->data
.normal
.enabled
= FALSE
;
169 return TRUE
; /* show the menu */
172 static void desktop_change_callback(ObClient
*c
, gpointer data
)
174 ObMenuFrame
*frame
= data
;
175 if (c
== frame
->client
) {
176 /* adding/removing entries while it's shown is not fun, so just hide
177 the menu and reshow it */
179 ObMenuEntryFrame
*me
= frame
->parent_entry
;
180 ObMenuFrame
*parent
= frame
->parent
;
182 g_list_position(frame
->entries
,
183 g_list_find(frame
->entries
, frame
->selected
));
184 menu_frame_select(parent
, NULL
, TRUE
);
185 menu_frame_select(parent
, me
, TRUE
);
187 frame
= parent
->child
;
188 /* reselect the same spot or the last one if it got shorter */
189 sel
= MIN(sel
, (gint
)g_list_length(frame
->entries
));
191 menu_frame_select(frame
,
192 g_list_nth(frame
->entries
, sel
)->data
,
195 menu_frame_hide(frame
);
199 static void show_callback(ObMenuFrame
*frame
, gpointer data
)
201 client_add_desktop_notify(desktop_change_callback
, frame
);
204 static void hide_callback(ObMenuFrame
*frame
, gpointer data
)
206 client_remove_desktop_notify(desktop_change_callback
);
209 static void client_menu_place(ObMenuFrame
*frame
, gint
*x
, gint
*y
,
210 gint button
, gpointer data
)
214 if (button
== 0 && frame
->client
) {
215 *x
= frame
->client
->frame
->area
.x
;
217 /* try below the titlebar */
218 *y
= frame
->client
->frame
->area
.y
+ frame
->client
->frame
->size
.top
-
219 frame
->client
->frame
->bwidth
;
220 menu_frame_move_on_screen(frame
, *x
, *y
, &dx
, &dy
);
222 /* try above the titlebar */
223 *y
= frame
->client
->frame
->area
.y
+ frame
->client
->frame
->bwidth
-
225 menu_frame_move_on_screen(frame
, *x
, *y
, &dx
, &dy
);
228 /* didnt fit either way, use move on screen's values */
229 *y
= frame
->client
->frame
->area
.y
+ frame
->client
->frame
->size
.top
;
230 menu_frame_move_on_screen(frame
, *x
, *y
, &dx
, &dy
);
241 /* try to the bottom right of the cursor */
242 menu_frame_move_on_screen(frame
, myx
, myy
, &dx
, &dy
);
243 if (dx
!= 0 || dy
!= 0) {
244 /* try to the bottom left of the cursor */
245 myx
= *x
- frame
->area
.width
;
247 menu_frame_move_on_screen(frame
, myx
, myy
, &dx
, &dy
);
249 if (dx
!= 0 || dy
!= 0) {
250 /* try to the top right of the cursor */
252 myy
= *y
- frame
->area
.height
;
253 menu_frame_move_on_screen(frame
, myx
, myy
, &dx
, &dy
);
255 if (dx
!= 0 || dy
!= 0) {
256 /* try to the top left of the cursor */
257 myx
= *x
- frame
->area
.width
;
258 myy
= *y
- frame
->area
.height
;
259 menu_frame_move_on_screen(frame
, myx
, myy
, &dx
, &dy
);
261 if (dx
!= 0 || dy
!= 0) {
262 /* if didnt fit on either side so just use what it says */
265 menu_frame_move_on_screen(frame
, myx
, myy
, &dx
, &dy
);
272 void client_menu_startup()
278 menu
= menu_new(LAYER_MENU_NAME
, _("&Layer"), TRUE
, NULL
);
279 menu_show_all_shortcuts(menu
, TRUE
);
280 menu_set_update_func(menu
, layer_update
);
282 acts
= g_slist_prepend(NULL
, action_from_string
283 ("SendToTopLayer", OB_USER_ACTION_MENU_SELECTION
));
284 menu_add_normal(menu
, LAYER_TOP
, _("Always on &top"), acts
, TRUE
);
286 acts
= g_slist_prepend(NULL
, action_from_string
287 ("SendToNormalLayer",
288 OB_USER_ACTION_MENU_SELECTION
));
289 menu_add_normal(menu
, LAYER_NORMAL
, _("&Normal"), acts
, TRUE
);
291 acts
= g_slist_prepend(NULL
, action_from_string
292 ("SendToBottomLayer",
293 OB_USER_ACTION_MENU_SELECTION
));
294 menu_add_normal(menu
, LAYER_BOTTOM
, _("Always on &bottom"),acts
, TRUE
);
297 menu
= menu_new(SEND_TO_MENU_NAME
, _("&Send to desktop"), TRUE
, NULL
);
298 menu_set_update_func(menu
, send_to_update
);
299 menu_set_show_func(menu
, show_callback
);
300 menu_set_hide_func(menu
, hide_callback
);
303 menu
= menu_new(CLIENT_MENU_NAME
, _("Client menu"), TRUE
, NULL
);
304 menu_show_all_shortcuts(menu
, TRUE
);
305 menu_set_update_func(menu
, client_update
);
306 menu_set_place_func(menu
, client_menu_place
);
308 acts
= g_slist_prepend(NULL
, action_from_string
309 ("ToggleMaximizeFull",
310 OB_USER_ACTION_MENU_SELECTION
));
311 e
= menu_add_normal(menu
, CLIENT_RESTORE
, _("R&estore"), acts
, TRUE
);
312 e
->data
.normal
.mask
= ob_rr_theme
->max_toggled_mask
;
313 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
314 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
315 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
316 e
->data
.normal
.mask_disabled_selected_color
=
317 ob_rr_theme
->menu_disabled_selected_color
;
319 acts
= g_slist_prepend(NULL
, action_from_string
320 ("Move", OB_USER_ACTION_MENU_SELECTION
));
321 menu_add_normal(menu
, CLIENT_MOVE
, _("&Move"), acts
, TRUE
);
323 acts
= g_slist_prepend(NULL
, action_from_string
324 ("Resize", OB_USER_ACTION_MENU_SELECTION
));
325 menu_add_normal(menu
, CLIENT_RESIZE
, _("Resi&ze"), acts
, TRUE
);
327 acts
= g_slist_prepend(NULL
, action_from_string
328 ("Iconify", OB_USER_ACTION_MENU_SELECTION
));
329 e
= menu_add_normal(menu
, CLIENT_ICONIFY
, _("Ico&nify"), acts
, TRUE
);
330 e
->data
.normal
.mask
= ob_rr_theme
->iconify_mask
;
331 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
332 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
333 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
334 e
->data
.normal
.mask_disabled_selected_color
=
335 ob_rr_theme
->menu_disabled_selected_color
;
337 acts
= g_slist_prepend(NULL
, action_from_string
338 ("ToggleMaximizeFull",
339 OB_USER_ACTION_MENU_SELECTION
));
340 e
= menu_add_normal(menu
, CLIENT_MAXIMIZE
, _("Ma&ximize"), acts
, TRUE
);
341 e
->data
.normal
.mask
= ob_rr_theme
->max_mask
;
342 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
343 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
344 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
345 e
->data
.normal
.mask_disabled_selected_color
=
346 ob_rr_theme
->menu_disabled_selected_color
;
348 acts
= g_slist_prepend(NULL
, action_from_string
349 ("ToggleShade", OB_USER_ACTION_MENU_SELECTION
));
350 e
= menu_add_normal(menu
, CLIENT_SHADE
, _("&Roll up/down"), acts
, TRUE
);
351 e
->data
.normal
.mask
= ob_rr_theme
->shade_mask
;
352 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
353 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
354 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
355 e
->data
.normal
.mask_disabled_selected_color
=
356 ob_rr_theme
->menu_disabled_selected_color
;
358 acts
= g_slist_prepend(NULL
, action_from_string
359 ("ToggleDecorations",
360 OB_USER_ACTION_MENU_SELECTION
));
361 menu_add_normal(menu
, CLIENT_DECORATE
, _("Un/&Decorate"), acts
, TRUE
);
363 menu_add_separator(menu
, -1, NULL
);
365 menu_add_submenu(menu
, CLIENT_SEND_TO
, SEND_TO_MENU_NAME
);
367 menu_add_submenu(menu
, CLIENT_LAYER
, LAYER_MENU_NAME
);
369 menu_add_separator(menu
, -1, NULL
);
371 acts
= g_slist_prepend(NULL
, action_from_string
372 ("Close", OB_USER_ACTION_MENU_SELECTION
));
373 e
= menu_add_normal(menu
, CLIENT_CLOSE
, _("&Close"), acts
, TRUE
);
374 e
->data
.normal
.mask
= ob_rr_theme
->close_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
;