]> icculus.org git repositories - dana/openbox.git/blob - openbox/apps_menu.c
WIP: Add an xdg applications menu (it doesn't have anything in it yet, but it does...
[dana/openbox.git] / openbox / apps_menu.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    apps_menu.c for the Openbox window manager
4    Copyright (c) 2011        Dana Jansens
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    See the COPYING file for a copy of the GNU General Public License.
17 */
18
19 #include "openbox.h"
20 #include "menu.h"
21 #include "menuframe.h"
22 #include "screen.h"
23 #include "apps_menu.h"
24 #include "config.h"
25 #include "gettext.h"
26 #include "obt/linkbase.h"
27 #include "obt/link.h"
28 #include "obt/paths.h"
29
30 #include <glib.h>
31
32 #define MENU_NAME "apps-menu"
33
34 static ObMenu *apps_menu;
35 static ObtLinkBase *linkbase;
36 static gboolean dirty;
37
38 static void self_destroy(ObMenu *menu, gpointer data)
39 {
40     obt_linkbase_unref(linkbase);
41     linkbase = NULL;
42 }
43
44 static void self_cleanup(ObMenu *menu, gpointer data)
45 {
46     menu_clear_entries(menu);
47 }
48
49 static gboolean self_update(ObMenuFrame *frame, gpointer data)
50 {
51     ObMenu *menu = frame->menu;
52     ObMenuEntry *e;
53
54     if (!dirty) return TRUE;  /* nothing has changed to be updated */
55
56 /*
57     menu_add_separator(menu, SEPARATOR, screen_desktop_names[desktop]);
58
59     gchar *title = g_strdup_printf("(%s)", c->icon_title);
60     e = menu_add_normal(menu, desktop, title, NULL, FALSE);
61     g_free(title);
62
63     if (config_menu_show_icons) {
64         e->data.normal.icon = client_icon(c);
65         RrImageRef(e->data.normal.icon);
66         e->data.normal.icon_alpha =
67             c->iconic ? OB_ICONIC_ALPHA : 0xff;
68     }
69
70     e->data.normal.data = link;
71 */
72
73     return TRUE; /* always show the menu */
74 }
75
76 static void menu_execute(ObMenuEntry *self, ObMenuFrame *f,
77                          ObClient *c, guint state, gpointer data)
78 {
79 #if 0
80     ObClient *t = self->data.normal.data;
81     if (t) { /* it's set to NULL if its destroyed */
82         gboolean here = state & ShiftMask;
83
84         client_activate(t, TRUE, here, TRUE, TRUE, TRUE);
85         /* if the window is omnipresent then we need to go to its
86            desktop */
87         if (!here && t->desktop == DESKTOP_ALL)
88             screen_set_desktop(self->id, FALSE);
89     }
90 #endif
91 }
92
93 void linkbase_update(ObtLinkBase *lb, gpointer data)
94 {
95     dirty = TRUE;
96 }
97
98 void apps_menu_startup(gboolean reconfig)
99 {
100     if (!reconfig) {
101         ObtPaths *paths;
102
103         paths = obt_paths_new();
104         /* XXX allow more environments, like GNOME or KDE, to be included */
105         linkbase = obt_linkbase_new(paths, ob_locale_msg,
106                                     OBT_LINK_ENV_OPENBOX);
107         obt_paths_unref(paths);
108     }
109
110     apps_menu = menu_new(MENU_NAME, _("Applications"), TRUE, NULL);
111     menu_set_update_func(apps_menu, self_update);
112     menu_set_cleanup_func(apps_menu, self_cleanup);
113     menu_set_execute_func(apps_menu, menu_execute);
114     menu_set_destroy_func(apps_menu, self_destroy);
115 }
116
117 void apps_menu_shutdown(gboolean reconfig)
118 {
119     /* freed by the hash table */
120 }