]> Dogcows Code - chaz/openbox/blob - openbox/client_menu.c
indenting
[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.enabled =frame->client->functions & OB_CLIENT_FUNC_MAXIMIZE;
76
77 e = menu_find_entry_id(menu, CLIENT_SHADE);
78 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_SHADE;
79
80 e = menu_find_entry_id(menu, CLIENT_MOVE);
81 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_MOVE;
82
83 e = menu_find_entry_id(menu, CLIENT_RESIZE);
84 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_RESIZE;
85
86 e = menu_find_entry_id(menu, CLIENT_CLOSE);
87 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_CLOSE;
88 }
89
90 static void layer_update(ObMenuFrame *frame, gpointer data)
91 {
92 ObMenu *menu = frame->menu;
93 ObMenuEntry *e;
94 GList *it;
95
96 for (it = menu->entries; it; it = g_list_next(it)) {
97 e = it->data;
98 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL)
99 e->data.normal.enabled = !!frame->client;
100 }
101
102 if (!frame->client)
103 return;
104
105 e = menu_find_entry_id(menu, LAYER_TOP);
106 e->data.normal.enabled = !frame->client->above;
107
108 e = menu_find_entry_id(menu, LAYER_NORMAL);
109 e->data.normal.enabled = (frame->client->above || frame->client->below);
110
111 e = menu_find_entry_id(menu, LAYER_BOTTOM);
112 e->data.normal.enabled = !frame->client->below;
113 }
114
115 static void send_to_update(ObMenuFrame *frame, gpointer data)
116 {
117 ObMenu *menu = frame->menu;
118 guint i;
119 GSList *acts;
120 ObAction *act;
121
122 menu_clear_entries(menu);
123
124 if (!frame->client)
125 return;
126
127 for (i = 0; i <= screen_num_desktops; ++i) {
128 gchar *name;
129 guint desk;
130
131 if (i >= screen_num_desktops) {
132 menu_add_separator(menu, -1);
133
134 desk = DESKTOP_ALL;
135 name = _("All desktops");
136 } else {
137 desk = i;
138 name = screen_desktop_names[i];
139 }
140
141 act = action_from_string("SendToDesktop",
142 OB_USER_ACTION_MENU_SELECTION);
143 act->data.sendto.desk = desk;
144 act->data.sendto.follow = FALSE;
145 acts = g_slist_prepend(NULL, act);
146 menu_add_normal(menu, desk, name, acts);
147
148 if (frame->client->desktop == desk) {
149 ObMenuEntry *e = menu_find_entry_id(menu, desk);
150 g_assert(e);
151 e->data.normal.enabled = FALSE;
152 }
153 }
154 }
155
156 void client_menu_startup()
157 {
158 GSList *acts;
159 ObMenu *menu;
160 ObMenuEntry *e;
161
162 menu = menu_new(LAYER_MENU_NAME, _("Layer"), NULL);
163 menu_set_update_func(menu, layer_update);
164
165 acts = g_slist_prepend(NULL, action_from_string
166 ("SendToTopLayer", OB_USER_ACTION_MENU_SELECTION));
167 menu_add_normal(menu, LAYER_TOP, _("Always on top"), acts);
168
169 acts = g_slist_prepend(NULL, action_from_string
170 ("SendToNormalLayer",
171 OB_USER_ACTION_MENU_SELECTION));
172 menu_add_normal(menu, LAYER_NORMAL, _("Normal"), acts);
173
174 acts = g_slist_prepend(NULL, action_from_string
175 ("SendToBottomLayer",
176 OB_USER_ACTION_MENU_SELECTION));
177 menu_add_normal(menu, LAYER_BOTTOM, _("Always on bottom"),acts);
178
179
180 menu = menu_new(SEND_TO_MENU_NAME, _("Send to desktop"), NULL);
181 menu_set_update_func(menu, send_to_update);
182
183
184 menu = menu_new(CLIENT_MENU_NAME, _("Client menu"), NULL);
185 menu_set_update_func(menu, client_update);
186
187 e = menu_add_submenu(menu, CLIENT_SEND_TO, SEND_TO_MENU_NAME);
188 e->data.normal.mask = ob_rr_theme->desk_mask;
189 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
190 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
191 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
192
193 menu_add_submenu(menu, CLIENT_LAYER, LAYER_MENU_NAME);
194
195 acts = g_slist_prepend(NULL, action_from_string
196 ("Iconify", OB_USER_ACTION_MENU_SELECTION));
197 e = menu_add_normal(menu, CLIENT_ICONIFY, _("Iconify"), acts);
198 e->data.normal.mask = ob_rr_theme->iconify_mask;
199 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
200 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
201 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
202
203 acts = g_slist_prepend(NULL, action_from_string
204 ("ToggleMaximizeFull",
205 OB_USER_ACTION_MENU_SELECTION));
206 e = menu_add_normal(menu, CLIENT_MAXIMIZE, _("Maximize"), acts);
207 e->data.normal.mask = ob_rr_theme->max_mask;
208 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
209 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
210 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
211
212 acts = g_slist_prepend(NULL, action_from_string
213 ("Raise", OB_USER_ACTION_MENU_SELECTION));
214 menu_add_normal(menu, CLIENT_RAISE, _("Raise to top"), acts);
215
216 acts = g_slist_prepend(NULL, action_from_string
217 ("Lower", OB_USER_ACTION_MENU_SELECTION));
218 menu_add_normal(menu, CLIENT_LOWER, _("Lower to bottom"),acts);
219
220 acts = g_slist_prepend(NULL, action_from_string
221 ("ToggleShade", OB_USER_ACTION_MENU_SELECTION));
222 e = menu_add_normal(menu, CLIENT_SHADE, _("Roll up/down"), acts);
223 e->data.normal.mask = ob_rr_theme->shade_mask;
224 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
225 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
226 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
227
228 acts = g_slist_prepend(NULL, action_from_string
229 ("ToggleDecorations",
230 OB_USER_ACTION_MENU_SELECTION));
231 menu_add_normal(menu, CLIENT_DECORATE, _("Decorate"), acts);
232
233 menu_add_separator(menu, -1);
234
235 acts = g_slist_prepend(NULL, action_from_string
236 ("Move", OB_USER_ACTION_MENU_SELECTION));
237 menu_add_normal(menu, CLIENT_MOVE, _("Move"), acts);
238
239 acts = g_slist_prepend(NULL, action_from_string
240 ("Resize", OB_USER_ACTION_MENU_SELECTION));
241 menu_add_normal(menu, CLIENT_RESIZE, _("Resize"), acts);
242
243 menu_add_separator(menu, -1);
244
245 acts = g_slist_prepend(NULL, action_from_string
246 ("Close", OB_USER_ACTION_MENU_SELECTION));
247 e = menu_add_normal(menu, CLIENT_CLOSE, _("Close"), acts);
248 e->data.normal.mask = ob_rr_theme->close_mask;
249 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
250 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
251 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
252 }
This page took 0.048513 seconds and 4 git commands to generate.