]> Dogcows Code - chaz/openbox/blob - plugins/menu/client_menu.c
d60f54507ee67dfc9b9db65a56cac93c1e767eb9
[chaz/openbox] / plugins / menu / client_menu.c
1 #include "kernel/debug.h"
2 #include "kernel/menu.h"
3 #include "kernel/menuframe.h"
4 #include "kernel/screen.h"
5 #include "kernel/client.h"
6 #include "kernel/openbox.h"
7 #include "kernel/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 void plugin_setup_config() { }
37
38 static void client_update(ObMenuFrame *frame, gpointer data)
39 {
40 ObMenu *menu = frame->menu;
41 ObMenuEntry *e;
42
43 frame->show_title = FALSE;
44
45 if (!frame->client) {
46 GList *it;
47
48 for (it = menu->entries; it; it = g_list_next(it)) {
49 ObMenuEntry *e = it->data;
50 e->enabled = FALSE;
51 }
52 return;
53 }
54
55 e = menu_find_entry_id(menu, CLIENT_ICONIFY);
56 e->enabled = frame->client->functions & OB_CLIENT_FUNC_ICONIFY;
57
58 e = menu_find_entry_id(menu, CLIENT_MAXIMIZE);
59 e->enabled = frame->client->functions & OB_CLIENT_FUNC_MAXIMIZE;
60
61 e = menu_find_entry_id(menu, CLIENT_SHADE);
62 e->enabled = frame->client->functions & OB_CLIENT_FUNC_SHADE;
63
64 e = menu_find_entry_id(menu, CLIENT_MOVE);
65 e->enabled = frame->client->functions & OB_CLIENT_FUNC_MOVE;
66
67 e = menu_find_entry_id(menu, CLIENT_RESIZE);
68 e->enabled = frame->client->functions & OB_CLIENT_FUNC_RESIZE;
69
70 e = menu_find_entry_id(menu, CLIENT_CLOSE);
71 e->enabled = frame->client->functions & OB_CLIENT_FUNC_CLOSE;
72 }
73
74 static void send_to_update(ObMenuFrame *frame, gpointer data)
75 {
76 ObMenu *menu = frame->menu;
77 guint i;
78 GSList *acts;
79 ObAction *act;
80
81 menu_clear_entries(SEND_TO_MENU_NAME);
82
83 if (!frame->client)
84 return;
85
86 for (i = 0; i <= screen_num_desktops; ++i) {
87 gchar *name;
88 guint desk;
89
90 if (i >= screen_num_desktops) {
91 desk = DESKTOP_ALL;
92 name = _("All desktops");
93 } else {
94 desk = i;
95 name = screen_desktop_names[i];
96 }
97
98 act = action_from_string("SendToDesktop");
99 act->data.sendto.desk = desk;
100 act->data.sendto.follow = FALSE;
101 acts = g_slist_prepend(NULL, act);
102 menu_add_normal(SEND_TO_MENU_NAME, desk, name, acts);
103
104 if (frame->client->desktop == desk) {
105 ObMenuEntry *e = menu_find_entry_id(menu, desk);
106 g_assert(e);
107 e->enabled = FALSE;
108 }
109 }
110 }
111
112 void plugin_startup()
113 {
114 GSList *acts;
115
116 menu_new(LAYER_MENU_NAME, _("Layer"), NULL);
117
118 acts = g_slist_prepend(NULL, action_from_string("SendToTopLayer"));
119 menu_add_normal(LAYER_MENU_NAME, LAYER_TOP, _("Always on top"), acts);
120
121 acts = g_slist_prepend(NULL, action_from_string("SendToNormalLayer"));
122 menu_add_normal(LAYER_MENU_NAME, LAYER_NORMAL, _("Normal"), acts);
123
124 acts = g_slist_prepend(NULL, action_from_string("SendToBottomLayer"));
125 menu_add_normal(LAYER_MENU_NAME, LAYER_BOTTOM, _("Always on bottom"),acts);
126
127
128 menu_new(SEND_TO_MENU_NAME, _("Send to desktop"), NULL);
129 menu_set_update_func(SEND_TO_MENU_NAME, send_to_update);
130
131 menu_new(CLIENT_MENU_NAME, _("Client menu"), NULL);
132 menu_set_update_func(CLIENT_MENU_NAME, client_update);
133
134 menu_add_submenu(CLIENT_MENU_NAME, CLIENT_SEND_TO, SEND_TO_MENU_NAME);
135
136 menu_add_submenu(CLIENT_MENU_NAME, CLIENT_LAYER, LAYER_MENU_NAME);
137
138 acts = g_slist_prepend(NULL, action_from_string("Iconify"));
139 menu_add_normal(CLIENT_MENU_NAME, CLIENT_ICONIFY, _("Iconify"), acts);
140
141 acts = g_slist_prepend(NULL, action_from_string("Maximize"));
142 menu_add_normal(CLIENT_MENU_NAME, CLIENT_MAXIMIZE, _("Maximize"), acts);
143
144 acts = g_slist_prepend(NULL, action_from_string("Raise"));
145 menu_add_normal(CLIENT_MENU_NAME, CLIENT_RAISE, _("Raise to top"), acts);
146
147 acts = g_slist_prepend(NULL, action_from_string("Lower"));
148 menu_add_normal(CLIENT_MENU_NAME, CLIENT_LOWER, _("Lower to bottom"),acts);
149
150 acts = g_slist_prepend(NULL, action_from_string("ToggleShade"));
151 menu_add_normal(CLIENT_MENU_NAME, CLIENT_SHADE, _("(Un)Shade"), acts);
152
153 acts = g_slist_prepend(NULL, action_from_string("ToggleDecorations"));
154 menu_add_normal(CLIENT_MENU_NAME, CLIENT_DECORATE, _("Decorate"), acts);
155
156 menu_add_separator(CLIENT_MENU_NAME, -1);
157
158 acts = g_slist_prepend(NULL, action_from_string("KeyboardMove"));
159 menu_add_normal(CLIENT_MENU_NAME, CLIENT_MOVE, _("Move"), acts);
160
161 acts = g_slist_prepend(NULL, action_from_string("KeyboardResize"));
162 menu_add_normal(CLIENT_MENU_NAME, CLIENT_RESIZE, _("Resize"), acts);
163
164 menu_add_separator(CLIENT_MENU_NAME, -1);
165
166 acts = g_slist_prepend(NULL, action_from_string("Close"));
167 menu_add_normal(CLIENT_MENU_NAME, CLIENT_CLOSE, _("Close"), acts);
168 }
169
170 void plugin_shutdown()
171 {
172 menu_free(LAYER_MENU_NAME);
173 menu_free(SEND_TO_MENU_NAME);
174 menu_free(CLIENT_MENU_NAME);
175 }
This page took 0.039078 seconds and 3 git commands to generate.