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"
54 static void client_update(ObMenuFrame
*frame
, gpointer data
)
56 ObMenu
*menu
= frame
->menu
;
60 for (it
= menu
->entries
; it
; it
= g_list_next(it
)) {
62 if (e
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
63 e
->data
.normal
.enabled
= !!frame
->client
;
69 e
= menu_find_entry_id(menu
, CLIENT_ICONIFY
);
70 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_ICONIFY
;
72 e
= menu_find_entry_id(menu
, CLIENT_MAXIMIZE
);
73 menu_entry_set_label(e
,
74 (frame
->client
->max_vert
|| frame
->client
->max_horz
?
75 _("Restor&e") : _("Maximiz&e")));
76 e
->data
.normal
.enabled
=frame
->client
->functions
& OB_CLIENT_FUNC_MAXIMIZE
;
78 e
= menu_find_entry_id(menu
, CLIENT_SHADE
);
79 menu_entry_set_label(e
, (frame
->client
->shaded
?
80 _("&Roll down") : _("&Roll up")));
81 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_SHADE
;
83 e
= menu_find_entry_id(menu
, CLIENT_MOVE
);
84 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_MOVE
;
86 e
= menu_find_entry_id(menu
, CLIENT_RESIZE
);
87 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_RESIZE
;
89 e
= menu_find_entry_id(menu
, CLIENT_CLOSE
);
90 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_CLOSE
;
92 e
= menu_find_entry_id(menu
, CLIENT_DECORATE
);
93 e
->data
.normal
.enabled
= client_normal(frame
->client
);
96 static void layer_update(ObMenuFrame
*frame
, gpointer data
)
98 ObMenu
*menu
= frame
->menu
;
102 for (it
= menu
->entries
; it
; it
= g_list_next(it
)) {
104 if (e
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
105 e
->data
.normal
.enabled
= !!frame
->client
;
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
;
121 static void send_to_update(ObMenuFrame
*frame
, gpointer data
)
123 ObMenu
*menu
= frame
->menu
;
129 menu_clear_entries(menu
);
134 for (i
= 0; i
<= screen_num_desktops
; ++i
) {
138 if (i
>= screen_num_desktops
) {
139 menu_add_separator(menu
, -1, NULL
);
142 name
= _("All desktops");
145 name
= screen_desktop_names
[i
];
148 act
= action_from_string("SendToDesktop",
149 OB_USER_ACTION_MENU_SELECTION
);
150 act
->data
.sendto
.desk
= desk
;
151 act
->data
.sendto
.follow
= FALSE
;
152 acts
= g_slist_prepend(NULL
, act
);
153 e
= menu_add_normal(menu
, desk
, name
, acts
);
155 if (frame
->client
->desktop
== desk
)
156 e
->data
.normal
.enabled
= FALSE
;
160 void client_menu_startup()
166 menu
= menu_new(LAYER_MENU_NAME
, _("&Layer"), NULL
);
167 menu_show_all_shortcuts(menu
, TRUE
);
168 menu_set_update_func(menu
, layer_update
);
170 acts
= g_slist_prepend(NULL
, action_from_string
171 ("SendToTopLayer", OB_USER_ACTION_MENU_SELECTION
));
172 menu_add_normal(menu
, LAYER_TOP
, _("Always on &top"), acts
);
174 acts
= g_slist_prepend(NULL
, action_from_string
175 ("SendToNormalLayer",
176 OB_USER_ACTION_MENU_SELECTION
));
177 menu_add_normal(menu
, LAYER_NORMAL
, _("&Normal"), acts
);
179 acts
= g_slist_prepend(NULL
, action_from_string
180 ("SendToBottomLayer",
181 OB_USER_ACTION_MENU_SELECTION
));
182 menu_add_normal(menu
, LAYER_BOTTOM
, _("Always on &bottom"),acts
);
185 menu
= menu_new(SEND_TO_MENU_NAME
, _("&Send to desktop"), NULL
);
186 menu_show_all_shortcuts(menu
, TRUE
);
187 menu_set_update_func(menu
, send_to_update
);
190 menu
= menu_new(CLIENT_MENU_NAME
, _("Client menu"), NULL
);
191 menu_show_all_shortcuts(menu
, TRUE
);
192 menu_set_update_func(menu
, client_update
);
194 menu_add_submenu(menu
, CLIENT_SEND_TO
, SEND_TO_MENU_NAME
);
196 menu_add_submenu(menu
, CLIENT_LAYER
, LAYER_MENU_NAME
);
198 acts
= g_slist_prepend(NULL
, action_from_string
199 ("Iconify", OB_USER_ACTION_MENU_SELECTION
));
200 e
= menu_add_normal(menu
, CLIENT_ICONIFY
, _("Ico&nify"), acts
);
201 e
->data
.normal
.mask
= ob_rr_theme
->iconify_mask
;
202 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
203 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
204 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
206 acts
= g_slist_prepend(NULL
, action_from_string
207 ("ToggleMaximizeFull",
208 OB_USER_ACTION_MENU_SELECTION
));
209 e
= menu_add_normal(menu
, CLIENT_MAXIMIZE
, "MAXIMIZE", acts
);
210 e
->data
.normal
.mask
= ob_rr_theme
->max_mask
;
211 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
212 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
213 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
215 acts
= g_slist_prepend(NULL
, action_from_string
216 ("Raise", OB_USER_ACTION_MENU_SELECTION
));
217 menu_add_normal(menu
, CLIENT_RAISE
, _("Raise to &top"), acts
);
219 acts
= g_slist_prepend(NULL
, action_from_string
220 ("Lower", OB_USER_ACTION_MENU_SELECTION
));
221 menu_add_normal(menu
, CLIENT_LOWER
, _("Lower to &bottom"),acts
);
223 acts
= g_slist_prepend(NULL
, action_from_string
224 ("ToggleShade", OB_USER_ACTION_MENU_SELECTION
));
225 e
= menu_add_normal(menu
, CLIENT_SHADE
, "SHADE", acts
);
226 e
->data
.normal
.mask
= ob_rr_theme
->shade_mask
;
227 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
228 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
229 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
231 acts
= g_slist_prepend(NULL
, action_from_string
232 ("ToggleDecorations",
233 OB_USER_ACTION_MENU_SELECTION
));
234 menu_add_normal(menu
, CLIENT_DECORATE
, _("&Decorate"), acts
);
236 menu_add_separator(menu
, -1, NULL
);
238 acts
= g_slist_prepend(NULL
, action_from_string
239 ("Move", OB_USER_ACTION_MENU_SELECTION
));
240 menu_add_normal(menu
, CLIENT_MOVE
, _("&Move"), acts
);
242 acts
= g_slist_prepend(NULL
, action_from_string
243 ("Resize", OB_USER_ACTION_MENU_SELECTION
));
244 menu_add_normal(menu
, CLIENT_RESIZE
, _("Resi&ze"), acts
);
246 menu_add_separator(menu
, -1, NULL
);
248 acts
= g_slist_prepend(NULL
, action_from_string
249 ("Close", OB_USER_ACTION_MENU_SELECTION
));
250 e
= menu_add_normal(menu
, CLIENT_CLOSE
, _("&Close"), acts
);
251 e
->data
.normal
.mask
= ob_rr_theme
->close_mask
;
252 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
253 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
254 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;