]> Dogcows Code - chaz/openbox/blob - plugins/menu/client_menu.c
931ee79dc47bcb730741fec5ff3742c2e49fc9cf
[chaz/openbox] / plugins / menu / client_menu.c
1 #include <glib.h>
2
3 #include "kernel/menu.h"
4 #include "kernel/screen.h"
5 #include "kernel/client.h"
6 #include "kernel/openbox.h"
7
8 #include "kernel/frame.h"
9
10 #include "render/theme.h"
11
12 static char *PLUGIN_NAME = "client_menu";
13
14 static ObMenu *send_to_menu;
15 static ObMenu *layer_menu;
16
17 typedef struct {
18 gint foo;
19 } Client_Menu_Data;
20
21 #define CLIENT_MENU(m) ((ObMenu *)m)
22 #define CLIENT_MENU_DATA(m) ((Client_Menu_Data *)((ObMenu *)m)->plugin_data)
23
24 void client_menu_clean_up(ObMenu *m) {
25 }
26
27 void client_send_to_update(ObMenu *self)
28 {
29 guint i = 0;
30 GList *it = self->entries;
31
32 /* check if we have to update. lame */
33 while (it != NULL) {
34 if (i >= screen_num_desktops)
35 break;
36 if (strcmp(screen_desktop_names[i],
37 ((ObMenuEntry *)it->data)->label) != 0)
38 break;
39 ++i;
40 it = it->next;
41 }
42
43 if (it != NULL || i != screen_num_desktops) {
44 menu_clear(self);
45 g_message("update");
46 for (i = 0; i < screen_num_desktops; ++i) {
47 ObMenuEntry *e;
48 Action *a = action_from_string("sendtodesktop");
49 a->data.sendto.desk = i;
50 a->data.sendto.follow = FALSE;
51 e = menu_entry_new(screen_desktop_names[i], a);
52 menu_add_entry(self, e);
53 }
54
55 menu_render_full(self);
56 }
57 }
58
59 void client_menu_show(ObMenu *self, int x, int y, ObClient *client)
60 {
61 guint i, newy, newx;
62 Rect *a = NULL;
63
64 g_assert(!self->invalid);
65 g_assert(client);
66
67 for (i = 0; i < screen_num_monitors; ++i) {
68 a = screen_physical_area_monitor(i);
69 if (RECT_CONTAINS(*a, x, y))
70 break;
71 }
72 g_assert(a != NULL);
73 self->xin_area = i;
74
75 newx = MAX(x, client->area.x);
76 newy = MAX(y, client->area.y);
77 POINT_SET(self->location,
78 MIN(newx, client->area.x + client->area.width - self->size.width),
79 MIN(newy, client->area.y + client->area.height -
80 self->size.height));
81
82 XMoveWindow(ob_display, self->frame, self->location.x, self->location.y);
83
84 if (!self->shown) {
85 XMapWindow(ob_display, self->frame);
86 stacking_raise(MENU_AS_WINDOW(self));
87 self->shown = TRUE;
88 } else if (self->shown && self->open_submenu) {
89 menu_hide(self->open_submenu);
90 }
91 }
92
93 void plugin_setup_config() { }
94
95 void plugin_shutdown() { }
96
97 void plugin_destroy (ObMenu *m)
98 {
99 }
100
101 void *plugin_create() /* TODO: need config */
102 {
103 ObMenu *m = menu_new_full(NULL, "client-menu", NULL,
104 client_menu_show, NULL);
105 m->plugin = PLUGIN_NAME;
106 menu_add_entry(m, menu_entry_new_submenu("Send To Workspace",
107 send_to_menu));
108 send_to_menu->parent = m;
109
110 menu_add_entry(m, menu_entry_new("Iconify",
111 action_from_string("iconify")));
112 menu_add_entry(m, menu_entry_new("Raise",
113 action_from_string("raise")));
114 menu_add_entry(m, menu_entry_new("Lower",
115 action_from_string("lower")));
116 menu_add_entry(m, menu_entry_new("Close",
117 action_from_string("close")));
118 menu_add_entry(m, menu_entry_new("Shade",
119 action_from_string("toggleshade")));
120 menu_add_entry(m, menu_entry_new("Omnipresent",
121 action_from_string("toggleomnipresent")));
122 menu_add_entry(m, menu_entry_new("Decorations",
123 action_from_string("toggledecorations")));
124 menu_add_entry(m, menu_entry_new_submenu("Layers",
125 layer_menu));
126 layer_menu->parent = m;
127
128 /* send to desktop
129 iconify
130 raise
131 lower
132 close
133 kill
134 shade
135 omnipresent
136 decorations
137 */
138 return (void *)m;
139 }
140
141 void plugin_startup()
142 {
143 ObMenu *t;
144 /* create a Send To Workspace ObMenu */
145 send_to_menu = menu_new_full(NULL, "send-to-workspace",
146 NULL, NULL, client_send_to_update);
147
148 layer_menu = menu_new(NULL, "layer", NULL);
149 menu_add_entry(layer_menu, menu_entry_new("Top Layer",
150 action_from_string("sendtotoplayer")));
151 menu_add_entry(layer_menu, menu_entry_new("Normal Layer",
152 action_from_string("sendtonormallayer")));
153 menu_add_entry(layer_menu, menu_entry_new("Bottom Layer",
154 action_from_string("sendtobottomlayer")));
155
156 t = (ObMenu *)plugin_create("client_menu");
157 }
158
This page took 0.040323 seconds and 3 git commands to generate.