]> Dogcows Code - chaz/openbox/blob - plugins/menu/client_menu.c
I had a commit message but my commit got stepped on so fuck it.
[chaz/openbox] / plugins / menu / client_menu.c
1 #include "kernel/debug.h"
2 #include "kernel/menu.h"
3 #include "kernel/screen.h"
4 #include "kernel/client.h"
5 #include "kernel/openbox.h"
6 #include "kernel/frame.h"
7
8 #include "render/theme.h"
9
10 #include <glib.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 ob_debug("update\n");
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 self->update(self);
56 }
57 }
58
59 void client_menu_show(ObMenu *self, int x, int y, ObClient *client)
60 {
61 guint i;
62 gint newy, newx;
63 Rect *a = NULL;
64
65 g_assert(!self->invalid);
66 g_assert(client);
67
68 for (i = 0; i < screen_num_monitors; ++i) {
69 a = screen_physical_area_monitor(i);
70 if (RECT_CONTAINS(*a, x, y))
71 break;
72 }
73 g_assert(a != NULL);
74 self->xin_area = i;
75
76 newx = MAX(x, client->area.x);
77 newy = MAX(y, client->area.y);
78 POINT_SET(self->location,
79 MIN(newx, client->area.x + client->area.width - self->size.width),
80 MIN(newy, client->area.y + client->area.height -
81 self->size.height));
82
83 XMoveWindow(ob_display, self->frame, self->location.x, self->location.y);
84
85 if (!self->shown) {
86 XMapWindow(ob_display, self->frame);
87 stacking_raise(MENU_AS_WINDOW(self));
88 self->shown = TRUE;
89 } else if (self->shown && self->open_submenu) {
90 menu_hide(self->open_submenu);
91 }
92 }
93
94 void plugin_setup_config() { }
95
96 void plugin_shutdown() { }
97
98 void plugin_destroy (ObMenu *m)
99 {
100 }
101
102 void *plugin_create() /* TODO: need config */
103 {
104 ObMenu *m = menu_new_full(NULL, "client-menu", NULL,
105 client_menu_show, NULL, NULL, NULL, NULL);
106 m->plugin = PLUGIN_NAME;
107 menu_add_entry(m, menu_entry_new_submenu("Send To Workspace",
108 send_to_menu));
109 send_to_menu->parent = m;
110
111 menu_add_entry(m, menu_entry_new("Iconify",
112 action_from_string("iconify")));
113 menu_add_entry(m, menu_entry_new("Raise",
114 action_from_string("raise")));
115 menu_add_entry(m, menu_entry_new("Lower",
116 action_from_string("lower")));
117 menu_add_entry(m, menu_entry_new("Close",
118 action_from_string("close")));
119 menu_add_entry(m, menu_entry_new("Shade",
120 action_from_string("toggleshade")));
121 menu_add_entry(m, menu_entry_new("Omnipresent",
122 action_from_string("toggleomnipresent")));
123 menu_add_entry(m, menu_entry_new("Decorations",
124 action_from_string("toggledecorations")));
125 menu_add_entry(m, menu_entry_new_submenu("Layers",
126 layer_menu));
127 layer_menu->parent = m;
128
129 /* send to desktop
130 iconify
131 raise
132 lower
133 close
134 kill
135 shade
136 omnipresent
137 decorations
138 */
139 return (void *)m;
140 }
141
142 void plugin_startup()
143 {
144 ObMenu *t;
145 /* create a Send To Workspace ObMenu */
146 send_to_menu = menu_new_full(NULL, "send-to-workspace",
147 NULL, NULL, client_send_to_update, NULL, NULL, NULL);
148
149 layer_menu = menu_new(NULL, "layer", NULL);
150 menu_add_entry(layer_menu, menu_entry_new("Top Layer",
151 action_from_string("sendtotoplayer")));
152 menu_add_entry(layer_menu, menu_entry_new("Normal Layer",
153 action_from_string("sendtonormallayer")));
154 menu_add_entry(layer_menu, menu_entry_new("Bottom Layer",
155 action_from_string("sendtobottomlayer")));
156
157 t = (ObMenu *)plugin_create("client_menu");
158 }
159
This page took 0.048735 seconds and 5 git commands to generate.