]> Dogcows Code - chaz/openbox/blob - openbox/client_menu.c
handle case where session saves a 0 width/height (for maximized windows!)
[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 Ben 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 "gettext.h"
27
28 #include <glib.h>
29
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"
33
34 enum {
35 LAYER_TOP,
36 LAYER_NORMAL,
37 LAYER_BOTTOM
38 };
39
40 enum {
41 CLIENT_SEND_TO,
42 CLIENT_LAYER,
43 CLIENT_ICONIFY,
44 CLIENT_MAXIMIZE,
45 CLIENT_RAISE,
46 CLIENT_LOWER,
47 CLIENT_SHADE,
48 CLIENT_DECORATE,
49 CLIENT_MOVE,
50 CLIENT_RESIZE,
51 CLIENT_CLOSE
52 };
53
54 static void client_update(ObMenuFrame *frame, gpointer data)
55 {
56 ObMenu *menu = frame->menu;
57 ObMenuEntry *e;
58 GList *it;
59
60 frame->show_title = FALSE;
61
62 for (it = menu->entries; it; it = g_list_next(it)) {
63 e = it->data;
64 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL)
65 e->data.normal.enabled = !!frame->client;
66 }
67
68 if (!frame->client)
69 return;
70
71 e = menu_find_entry_id(menu, CLIENT_ICONIFY);
72 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_ICONIFY;
73
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;
78
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;
83
84 e = menu_find_entry_id(menu, CLIENT_MOVE);
85 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_MOVE;
86
87 e = menu_find_entry_id(menu, CLIENT_RESIZE);
88 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_RESIZE;
89
90 e = menu_find_entry_id(menu, CLIENT_CLOSE);
91 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_CLOSE;
92
93 e = menu_find_entry_id(menu, CLIENT_DECORATE);
94 e->data.normal.enabled = client_normal(frame->client);
95 }
96
97 static void layer_update(ObMenuFrame *frame, gpointer data)
98 {
99 ObMenu *menu = frame->menu;
100 ObMenuEntry *e;
101 GList *it;
102
103 for (it = menu->entries; it; it = g_list_next(it)) {
104 e = it->data;
105 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL)
106 e->data.normal.enabled = !!frame->client;
107 }
108
109 if (!frame->client)
110 return;
111
112 e = menu_find_entry_id(menu, LAYER_TOP);
113 e->data.normal.enabled = !frame->client->above;
114
115 e = menu_find_entry_id(menu, LAYER_NORMAL);
116 e->data.normal.enabled = (frame->client->above || frame->client->below);
117
118 e = menu_find_entry_id(menu, LAYER_BOTTOM);
119 e->data.normal.enabled = !frame->client->below;
120 }
121
122 static void send_to_update(ObMenuFrame *frame, gpointer data)
123 {
124 ObMenu *menu = frame->menu;
125 guint i;
126 GSList *acts;
127 ObAction *act;
128
129 menu_clear_entries(menu);
130
131 if (!frame->client)
132 return;
133
134 for (i = 0; i <= screen_num_desktops; ++i) {
135 gchar *name;
136 guint desk;
137
138 if (i >= screen_num_desktops) {
139 menu_add_separator(menu, -1);
140
141 desk = DESKTOP_ALL;
142 name = _("All desktops");
143 } else {
144 desk = i;
145 name = screen_desktop_names[i];
146 }
147
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 menu_add_normal(menu, desk, name, acts);
154
155 if (frame->client->desktop == desk) {
156 ObMenuEntry *e = menu_find_entry_id(menu, desk);
157 g_assert(e);
158 e->data.normal.enabled = FALSE;
159 }
160 }
161 }
162
163 void client_menu_startup()
164 {
165 GSList *acts;
166 ObMenu *menu;
167 ObMenuEntry *e;
168
169 menu = menu_new(LAYER_MENU_NAME, _("Layer"), NULL);
170 menu_set_update_func(menu, layer_update);
171
172 acts = g_slist_prepend(NULL, action_from_string
173 ("SendToTopLayer", OB_USER_ACTION_MENU_SELECTION));
174 menu_add_normal(menu, LAYER_TOP, _("Always on top"), acts);
175
176 acts = g_slist_prepend(NULL, action_from_string
177 ("SendToNormalLayer",
178 OB_USER_ACTION_MENU_SELECTION));
179 menu_add_normal(menu, LAYER_NORMAL, _("Normal"), acts);
180
181 acts = g_slist_prepend(NULL, action_from_string
182 ("SendToBottomLayer",
183 OB_USER_ACTION_MENU_SELECTION));
184 menu_add_normal(menu, LAYER_BOTTOM, _("Always on bottom"),acts);
185
186
187 menu = menu_new(SEND_TO_MENU_NAME, _("Send to desktop"), NULL);
188 menu_set_update_func(menu, send_to_update);
189
190
191 menu = menu_new(CLIENT_MENU_NAME, _("Client menu"), NULL);
192 menu_set_update_func(menu, client_update);
193
194 e = menu_add_submenu(menu, CLIENT_SEND_TO, SEND_TO_MENU_NAME);
195 e->data.normal.mask = ob_rr_theme->desk_mask;
196 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
197 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
198 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
199
200 menu_add_submenu(menu, CLIENT_LAYER, LAYER_MENU_NAME);
201
202 acts = g_slist_prepend(NULL, action_from_string
203 ("Iconify", OB_USER_ACTION_MENU_SELECTION));
204 e = menu_add_normal(menu, CLIENT_ICONIFY, _("Iconify"), acts);
205 e->data.normal.mask = ob_rr_theme->iconify_mask;
206 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
207 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
208 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
209
210 acts = g_slist_prepend(NULL, action_from_string
211 ("ToggleMaximizeFull",
212 OB_USER_ACTION_MENU_SELECTION));
213 e = menu_add_normal(menu, CLIENT_MAXIMIZE, "MAXIMIZE", acts);
214 e->data.normal.mask = ob_rr_theme->max_mask;
215 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
216 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
217 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
218
219 acts = g_slist_prepend(NULL, action_from_string
220 ("Raise", OB_USER_ACTION_MENU_SELECTION));
221 menu_add_normal(menu, CLIENT_RAISE, _("Raise to top"), acts);
222
223 acts = g_slist_prepend(NULL, action_from_string
224 ("Lower", OB_USER_ACTION_MENU_SELECTION));
225 menu_add_normal(menu, CLIENT_LOWER, _("Lower to bottom"),acts);
226
227 acts = g_slist_prepend(NULL, action_from_string
228 ("ToggleShade", OB_USER_ACTION_MENU_SELECTION));
229 e = menu_add_normal(menu, CLIENT_SHADE, "SHADE", acts);
230 e->data.normal.mask = ob_rr_theme->shade_mask;
231 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
232 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
233 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
234
235 acts = g_slist_prepend(NULL, action_from_string
236 ("ToggleDecorations",
237 OB_USER_ACTION_MENU_SELECTION));
238 menu_add_normal(menu, CLIENT_DECORATE, _("Decorate"), acts);
239
240 menu_add_separator(menu, -1);
241
242 acts = g_slist_prepend(NULL, action_from_string
243 ("Move", OB_USER_ACTION_MENU_SELECTION));
244 menu_add_normal(menu, CLIENT_MOVE, _("Move"), acts);
245
246 acts = g_slist_prepend(NULL, action_from_string
247 ("Resize", OB_USER_ACTION_MENU_SELECTION));
248 menu_add_normal(menu, CLIENT_RESIZE, _("Resize"), acts);
249
250 menu_add_separator(menu, -1);
251
252 acts = g_slist_prepend(NULL, action_from_string
253 ("Close", OB_USER_ACTION_MENU_SELECTION));
254 e = menu_add_normal(menu, CLIENT_CLOSE, _("Close"), acts);
255 e->data.normal.mask = ob_rr_theme->close_mask;
256 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
257 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
258 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
259 }
This page took 0.045958 seconds and 4 git commands to generate.