]> Dogcows Code - chaz/openbox/blob - openbox/client_menu.c
dc724383e4319366f530f7d426d15be47cb0a546
[chaz/openbox] / openbox / client_menu.c
1 #include "debug.h"
2 #include "menu.h"
3 #include "menuframe.h"
4 #include "screen.h"
5 #include "client.h"
6 #include "openbox.h"
7 #include "frame.h"
8 #include "gettext.h"
9
10 #include <glib.h>
11
12 #define CLIENT_MENU_NAME "client-menu"
13 #define SEND_TO_MENU_NAME "client-send-to-menu"
14 #define LAYER_MENU_NAME "client-layer-menu"
15
16 enum {
17 LAYER_TOP,
18 LAYER_NORMAL,
19 LAYER_BOTTOM
20 };
21
22 enum {
23 CLIENT_SEND_TO,
24 CLIENT_LAYER,
25 CLIENT_ICONIFY,
26 CLIENT_MAXIMIZE,
27 CLIENT_RAISE,
28 CLIENT_LOWER,
29 CLIENT_SHADE,
30 CLIENT_DECORATE,
31 CLIENT_MOVE,
32 CLIENT_RESIZE,
33 CLIENT_CLOSE
34 };
35
36 static void client_update(ObMenuFrame *frame, gpointer data)
37 {
38 ObMenu *menu = frame->menu;
39 ObMenuEntry *e;
40 GList *it;
41
42 frame->show_title = FALSE;
43
44 for (it = menu->entries; it; it = g_list_next(it)) {
45 e = it->data;
46 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL)
47 e->data.normal.enabled = !!frame->client;
48 }
49
50 if (!frame->client)
51 return;
52
53 e = menu_find_entry_id(menu, CLIENT_ICONIFY);
54 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_ICONIFY;
55
56 e = menu_find_entry_id(menu, CLIENT_MAXIMIZE);
57 e->data.normal.enabled =frame->client->functions & OB_CLIENT_FUNC_MAXIMIZE;
58
59 e = menu_find_entry_id(menu, CLIENT_SHADE);
60 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_SHADE;
61
62 e = menu_find_entry_id(menu, CLIENT_MOVE);
63 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_MOVE;
64
65 e = menu_find_entry_id(menu, CLIENT_RESIZE);
66 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_RESIZE;
67
68 e = menu_find_entry_id(menu, CLIENT_CLOSE);
69 e->data.normal.enabled = frame->client->functions & OB_CLIENT_FUNC_CLOSE;
70 }
71
72 static void layer_update(ObMenuFrame *frame, gpointer data)
73 {
74 ObMenu *menu = frame->menu;
75 ObMenuEntry *e;
76 GList *it;
77
78 for (it = menu->entries; it; it = g_list_next(it)) {
79 e = it->data;
80 if (e->type == OB_MENU_ENTRY_TYPE_NORMAL)
81 e->data.normal.enabled = !!frame->client;
82 }
83
84 if (!frame->client)
85 return;
86
87 e = menu_find_entry_id(menu, LAYER_TOP);
88 e->data.normal.enabled = !frame->client->above;
89
90 e = menu_find_entry_id(menu, LAYER_NORMAL);
91 e->data.normal.enabled = (frame->client->above || frame->client->below);
92
93 e = menu_find_entry_id(menu, LAYER_BOTTOM);
94 e->data.normal.enabled = !frame->client->below;
95 }
96
97 static void send_to_update(ObMenuFrame *frame, gpointer data)
98 {
99 ObMenu *menu = frame->menu;
100 guint i;
101 GSList *acts;
102 ObAction *act;
103
104 menu_clear_entries(menu);
105
106 if (!frame->client)
107 return;
108
109 for (i = 0; i <= screen_num_desktops; ++i) {
110 gchar *name;
111 guint desk;
112
113 if (i >= screen_num_desktops) {
114 menu_add_separator(menu, -1);
115
116 desk = DESKTOP_ALL;
117 name = _("All desktops");
118 } else {
119 desk = i;
120 name = screen_desktop_names[i];
121 }
122
123 act = action_from_string("SendToDesktop");
124 act->data.sendto.desk = desk;
125 act->data.sendto.follow = FALSE;
126 acts = g_slist_prepend(NULL, act);
127 menu_add_normal(menu, desk, name, acts);
128
129 if (frame->client->desktop == desk) {
130 ObMenuEntry *e = menu_find_entry_id(menu, desk);
131 g_assert(e);
132 e->data.normal.enabled = FALSE;
133 }
134 }
135 }
136
137 void client_menu_startup()
138 {
139 GSList *acts;
140 ObMenu *menu;
141 ObMenuEntry *e;
142
143 menu = menu_new(LAYER_MENU_NAME, _("Layer"), NULL);
144 menu_set_update_func(menu, layer_update);
145
146 acts = g_slist_prepend(NULL, action_from_string("SendToTopLayer"));
147 menu_add_normal(menu, LAYER_TOP, _("Always on top"), acts);
148
149 acts = g_slist_prepend(NULL, action_from_string("SendToNormalLayer"));
150 menu_add_normal(menu, LAYER_NORMAL, _("Normal"), acts);
151
152 acts = g_slist_prepend(NULL, action_from_string("SendToBottomLayer"));
153 menu_add_normal(menu, LAYER_BOTTOM, _("Always on bottom"),acts);
154
155
156 menu = menu_new(SEND_TO_MENU_NAME, _("Send to desktop"), NULL);
157 menu_set_update_func(menu, send_to_update);
158
159
160 menu = menu_new(CLIENT_MENU_NAME, _("Client menu"), NULL);
161 menu_set_update_func(menu, client_update);
162
163 e = menu_add_submenu(menu, CLIENT_SEND_TO, SEND_TO_MENU_NAME);
164 e->data.normal.mask = ob_rr_theme->desk_mask;
165 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
166 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
167 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
168
169 menu_add_submenu(menu, CLIENT_LAYER, LAYER_MENU_NAME);
170
171 acts = g_slist_prepend(NULL, action_from_string("Iconify"));
172 e = menu_add_normal(menu, CLIENT_ICONIFY, _("Iconify"), acts);
173 e->data.normal.mask = ob_rr_theme->iconify_mask;
174 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
175 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
176 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
177
178 acts = g_slist_prepend(NULL, action_from_string("ToggleMaximizeFull"));
179 e = menu_add_normal(menu, CLIENT_MAXIMIZE, _("Maximize"), acts);
180 e->data.normal.mask = ob_rr_theme->max_mask;
181 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
182 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
183 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
184
185 acts = g_slist_prepend(NULL, action_from_string("Raise"));
186 menu_add_normal(menu, CLIENT_RAISE, _("Raise to top"), acts);
187
188 acts = g_slist_prepend(NULL, action_from_string("Lower"));
189 menu_add_normal(menu, CLIENT_LOWER, _("Lower to bottom"),acts);
190
191 acts = g_slist_prepend(NULL, action_from_string("ToggleShade"));
192 e = menu_add_normal(menu, CLIENT_SHADE, _("Roll up/down"), acts);
193 e->data.normal.mask = ob_rr_theme->shade_mask;
194 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
195 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
196 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
197
198 acts = g_slist_prepend(NULL, action_from_string("ToggleDecorations"));
199 menu_add_normal(menu, CLIENT_DECORATE, _("Decorate"), acts);
200
201 menu_add_separator(menu, -1);
202
203 acts = g_slist_prepend(NULL, action_from_string("KeyboardMove"));
204 menu_add_normal(menu, CLIENT_MOVE, _("Move"), acts);
205
206 acts = g_slist_prepend(NULL, action_from_string("KeyboardResize"));
207 menu_add_normal(menu, CLIENT_RESIZE, _("Resize"), acts);
208
209 menu_add_separator(menu, -1);
210
211 acts = g_slist_prepend(NULL, action_from_string("Close"));
212 e = menu_add_normal(menu, CLIENT_CLOSE, _("Close"), acts);
213 e->data.normal.mask = ob_rr_theme->close_mask;
214 e->data.normal.mask_normal_color = ob_rr_theme->menu_color;
215 e->data.normal.mask_disabled_color = ob_rr_theme->menu_disabled_color;
216 e->data.normal.mask_selected_color = ob_rr_theme->menu_selected_color;
217 }
This page took 0.040218 seconds and 3 git commands to generate.