]> Dogcows Code - chaz/openbox/blob - plugins/menu/client_list_menu.c
054353fd7b6673d5cd038f7ad8ea9ea79e39a11d
[chaz/openbox] / plugins / menu / client_list_menu.c
1 #include "kernel/openbox.h"
2 #include "kernel/menu.h"
3 #include "kernel/menuframe.h"
4 #include "kernel/action.h"
5 #include "kernel/screen.h"
6 #include "kernel/client.h"
7 #include "kernel/focus.h"
8 #include "gettext.h"
9
10 #include "render/theme.h"
11
12 #include <glib.h>
13
14 #define MENU_NAME "client-list-menu"
15
16 typedef struct {
17 /* how many desktop menus we've made */
18 guint desktops;
19 } MenuData;
20
21 typedef struct {
22 guint desktop;
23 } DesktopData;
24
25 void plugin_setup_config() { }
26
27 static void desk_menu_update(ObMenuFrame *frame, gpointer data)
28 {
29 ObMenu *menu = frame->menu;
30 DesktopData *d = data;
31 GList *it;
32 gint i;
33
34 menu_clear_entries(menu->name);
35
36 for (it = focus_order[d->desktop], i = 0; it; it = g_list_next(it), ++i) {
37 ObClient *c = it->data;
38 if (client_normal(c)) {
39 GSList *acts;
40 ObAction* act;
41 ObMenuEntry *e;
42 ObClientIcon *icon;
43
44 act = action_from_string("activate");
45 act->data.activate.c = c;
46 acts = g_slist_prepend(NULL, act);
47 menu_add_normal(menu->name, i,
48 (c->iconic ? c->icon_title : c->title), acts);
49
50 if ((icon = client_icon(c, 32, 32))) {
51 e = menu_find_entry_id(menu, i);
52 e->data.normal.icon_width = icon->width;
53 e->data.normal.icon_height = icon->height;
54 e->data.normal.icon_data = icon->data;
55 }
56 }
57 }
58
59 }
60
61 /* executes it without changing the client in the actions, since we set that
62 when we make the actions! */
63 static void desk_menu_execute(ObMenuEntry *self, gpointer data)
64 {
65 GSList *it;
66
67 for (it = self->data.normal.actions; it; it = g_slist_next(it))
68 {
69 ObAction *act = it->data;
70 act->func(&act->data);
71 }
72 }
73
74 static void desk_menu_destroy(ObMenu *menu, gpointer data)
75 {
76 DesktopData *d = data;
77
78 g_free(d);
79 }
80
81 static void self_update(ObMenuFrame *frame, gpointer data)
82 {
83 guint i;
84 MenuData *d = data;
85
86 menu_clear_entries(MENU_NAME);
87
88 for (i = 0; i < screen_num_desktops; ++i) {
89 gchar *name = g_strdup_printf("%s-%u", MENU_NAME, i);
90 DesktopData *data = g_new(DesktopData, 1);
91
92 data->desktop = i;
93 menu_new(name, screen_desktop_names[i], data);
94 menu_set_update_func(name, desk_menu_update);
95 menu_set_execute_func(name, desk_menu_execute);
96 menu_set_destroy_func(name, desk_menu_destroy);
97
98 menu_add_submenu(MENU_NAME, 0, name);
99
100 g_free(name);
101 }
102
103 d->desktops = MAX(d->desktops, screen_num_desktops);
104 }
105
106 static void self_destroy(ObMenu *menu, gpointer data)
107 {
108 MenuData *d = data;
109 guint i;
110
111 for (i = 0; i < d->desktops; ++i) {
112 gchar *name = g_strdup_printf("%s-%u", MENU_NAME, i);
113 menu_free(name);
114 g_free(name);
115 }
116 g_free(d);
117 }
118
119 void plugin_startup()
120 {
121 MenuData *data;
122
123 data = g_new(MenuData, 1);
124 data->desktops = 0;
125 menu_new(MENU_NAME, _("Desktops"), data);
126 menu_set_update_func(MENU_NAME, self_update);
127 menu_set_destroy_func(MENU_NAME, self_destroy);
128 }
129
130 void plugin_shutdown()
131 {
132 menu_free(MENU_NAME);
133 }
This page took 0.03637 seconds and 3 git commands to generate.