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 Ben 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 frame
->show_title
= FALSE
;
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
= !!frame
->client
;
71 e
= menu_find_entry_id(menu
, CLIENT_ICONIFY
);
72 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_ICONIFY
;
74 e
= menu_find_entry_id(menu
, CLIENT_MAXIMIZE
);
75 e
->data
.normal
.label
= frame
->client
->max_vert
|| frame
->client
->max_horz
?
76 _("Restore") : _("Maximize");
77 e
->data
.normal
.enabled
=frame
->client
->functions
& OB_CLIENT_FUNC_MAXIMIZE
;
79 e
= menu_find_entry_id(menu
, CLIENT_SHADE
);
80 e
->data
.normal
.label
= frame
->client
->shaded
?
81 _("Roll down") : _("Roll up");
82 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_SHADE
;
84 e
= menu_find_entry_id(menu
, CLIENT_MOVE
);
85 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_MOVE
;
87 e
= menu_find_entry_id(menu
, CLIENT_RESIZE
);
88 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_RESIZE
;
90 e
= menu_find_entry_id(menu
, CLIENT_CLOSE
);
91 e
->data
.normal
.enabled
= frame
->client
->functions
& OB_CLIENT_FUNC_CLOSE
;
94 static void layer_update(ObMenuFrame
*frame
, gpointer data
)
96 ObMenu
*menu
= frame
->menu
;
100 for (it
= menu
->entries
; it
; it
= g_list_next(it
)) {
102 if (e
->type
== OB_MENU_ENTRY_TYPE_NORMAL
)
103 e
->data
.normal
.enabled
= !!frame
->client
;
109 e
= menu_find_entry_id(menu
, LAYER_TOP
);
110 e
->data
.normal
.enabled
= !frame
->client
->above
;
112 e
= menu_find_entry_id(menu
, LAYER_NORMAL
);
113 e
->data
.normal
.enabled
= (frame
->client
->above
|| frame
->client
->below
);
115 e
= menu_find_entry_id(menu
, LAYER_BOTTOM
);
116 e
->data
.normal
.enabled
= !frame
->client
->below
;
119 static void send_to_update(ObMenuFrame
*frame
, gpointer data
)
121 ObMenu
*menu
= frame
->menu
;
126 menu_clear_entries(menu
);
131 for (i
= 0; i
<= screen_num_desktops
; ++i
) {
135 if (i
>= screen_num_desktops
) {
136 menu_add_separator(menu
, -1);
139 name
= _("All desktops");
142 name
= screen_desktop_names
[i
];
145 act
= action_from_string("SendToDesktop",
146 OB_USER_ACTION_MENU_SELECTION
);
147 act
->data
.sendto
.desk
= desk
;
148 act
->data
.sendto
.follow
= FALSE
;
149 acts
= g_slist_prepend(NULL
, act
);
150 menu_add_normal(menu
, desk
, name
, acts
);
152 if (frame
->client
->desktop
== desk
) {
153 ObMenuEntry
*e
= menu_find_entry_id(menu
, desk
);
155 e
->data
.normal
.enabled
= FALSE
;
160 void client_menu_startup()
166 menu
= menu_new(LAYER_MENU_NAME
, _("Layer"), NULL
);
167 menu_set_update_func(menu
, layer_update
);
169 acts
= g_slist_prepend(NULL
, action_from_string
170 ("SendToTopLayer", OB_USER_ACTION_MENU_SELECTION
));
171 menu_add_normal(menu
, LAYER_TOP
, _("Always on top"), acts
);
173 acts
= g_slist_prepend(NULL
, action_from_string
174 ("SendToNormalLayer",
175 OB_USER_ACTION_MENU_SELECTION
));
176 menu_add_normal(menu
, LAYER_NORMAL
, _("Normal"), acts
);
178 acts
= g_slist_prepend(NULL
, action_from_string
179 ("SendToBottomLayer",
180 OB_USER_ACTION_MENU_SELECTION
));
181 menu_add_normal(menu
, LAYER_BOTTOM
, _("Always on bottom"),acts
);
184 menu
= menu_new(SEND_TO_MENU_NAME
, _("Send to desktop"), NULL
);
185 menu_set_update_func(menu
, send_to_update
);
188 menu
= menu_new(CLIENT_MENU_NAME
, _("Client menu"), NULL
);
189 menu_set_update_func(menu
, client_update
);
191 e
= menu_add_submenu(menu
, CLIENT_SEND_TO
, SEND_TO_MENU_NAME
);
192 e
->data
.normal
.mask
= ob_rr_theme
->desk_mask
;
193 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
194 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
195 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
197 menu_add_submenu(menu
, CLIENT_LAYER
, LAYER_MENU_NAME
);
199 acts
= g_slist_prepend(NULL
, action_from_string
200 ("Iconify", OB_USER_ACTION_MENU_SELECTION
));
201 e
= menu_add_normal(menu
, CLIENT_ICONIFY
, _("Iconify"), acts
);
202 e
->data
.normal
.mask
= ob_rr_theme
->iconify_mask
;
203 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
204 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
205 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
207 acts
= g_slist_prepend(NULL
, action_from_string
208 ("ToggleMaximizeFull",
209 OB_USER_ACTION_MENU_SELECTION
));
210 e
= menu_add_normal(menu
, CLIENT_MAXIMIZE
, "MAXIMIZE", acts
);
211 e
->data
.normal
.mask
= ob_rr_theme
->max_mask
;
212 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
213 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
214 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
216 acts
= g_slist_prepend(NULL
, action_from_string
217 ("Raise", OB_USER_ACTION_MENU_SELECTION
));
218 menu_add_normal(menu
, CLIENT_RAISE
, _("Raise to top"), acts
);
220 acts
= g_slist_prepend(NULL
, action_from_string
221 ("Lower", OB_USER_ACTION_MENU_SELECTION
));
222 menu_add_normal(menu
, CLIENT_LOWER
, _("Lower to bottom"),acts
);
224 acts
= g_slist_prepend(NULL
, action_from_string
225 ("ToggleShade", OB_USER_ACTION_MENU_SELECTION
));
226 e
= menu_add_normal(menu
, CLIENT_SHADE
, "SHADE", acts
);
227 e
->data
.normal
.mask
= ob_rr_theme
->shade_mask
;
228 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
229 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
230 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;
232 acts
= g_slist_prepend(NULL
, action_from_string
233 ("ToggleDecorations",
234 OB_USER_ACTION_MENU_SELECTION
));
235 menu_add_normal(menu
, CLIENT_DECORATE
, _("Decorate"), acts
);
237 menu_add_separator(menu
, -1);
239 acts
= g_slist_prepend(NULL
, action_from_string
240 ("Move", OB_USER_ACTION_MENU_SELECTION
));
241 menu_add_normal(menu
, CLIENT_MOVE
, _("Move"), acts
);
243 acts
= g_slist_prepend(NULL
, action_from_string
244 ("Resize", OB_USER_ACTION_MENU_SELECTION
));
245 menu_add_normal(menu
, CLIENT_RESIZE
, _("Resize"), acts
);
247 menu_add_separator(menu
, -1);
249 acts
= g_slist_prepend(NULL
, action_from_string
250 ("Close", OB_USER_ACTION_MENU_SELECTION
));
251 e
= menu_add_normal(menu
, CLIENT_CLOSE
, _("Close"), acts
);
252 e
->data
.normal
.mask
= ob_rr_theme
->close_mask
;
253 e
->data
.normal
.mask_normal_color
= ob_rr_theme
->menu_color
;
254 e
->data
.normal
.mask_disabled_color
= ob_rr_theme
->menu_disabled_color
;
255 e
->data
.normal
.mask_selected_color
= ob_rr_theme
->menu_selected_color
;