1 /*
2 * This file is part of brisk-menu.
3 *
4 * Copyright © 2016-2020 Brisk Menu Developers
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
12 #define _GNU_SOURCE
13
14 #include "config.h"
15 #include "util.h"
16
17 BRISK_BEGIN_PEDANTIC
18 #include "applet.h"
19 #include "brisk-resources.h"
20 #include <glib/gi18n.h>
21 #include <libnotify/notify.h>
22 #include <mate-panel-applet.h>
23 BRISK_END_PEDANTIC
24
25 DEF_AUTOFREE(GtkActionGroup, g_object_unref)
26
27 static gboolean notify_had_init = FALSE;
28
29 /**
30 * We have no .ctor in the .a file - so it doesn't link
31 */
brisk_resource_init(void)32 __attribute__((constructor)) static void brisk_resource_init(void)
33 {
34 brisk_resources_register_resource();
35 }
36
37 /**
38 * Again, no .dtor due to link issues, so we do it here
39 */
brisk_resource_deinit(void)40 __attribute__((destructor)) static void brisk_resource_deinit(void)
41 {
42 brisk_resources_unregister_resource();
43 }
44
45 /**
46 * Menu actions for right click on the button
47 */
48 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
49 static const GtkActionEntry brisk_actions[] = { {
50 "EditMenus",
51 GTK_STOCK_EDIT,
52 N_("_Edit Menus"),
53 NULL,
54 NULL,
55 G_CALLBACK(brisk_menu_applet_edit_menus),
56 },
57 {
58 "ShowAbout",
59 GTK_STOCK_ABOUT,
60 N_("_About"),
61 NULL,
62 NULL,
63 G_CALLBACK(brisk_menu_applet_show_about),
64 }
65
66 };
67 G_GNUC_END_IGNORE_DEPRECATIONS
68
69 /**
70 * UI definition for our right click menu
71 */
72 #define BRISK_MENU_XML \
73 "<menuitem name=\"Edit Menus\" action=\"EditMenus\" />" \
74 "<menuitem name=\"About\" action=\"ShowAbout\" />"
75
brisk_menu_applet_factory(MatePanelApplet * applet,const gchar * id,__brisk_unused__ gpointer v)76 static gboolean brisk_menu_applet_factory(MatePanelApplet *applet, const gchar *id,
77 __brisk_unused__ gpointer v)
78 {
79 if (!g_str_has_prefix(id, "BriskMenu")) {
80 return FALSE;
81 }
82 const char *home = NULL;
83 __attribute__((unused)) int ret = 0;
84 autofree(GtkActionGroup) *group = NULL;
85
86 home = g_get_home_dir();
87 if (home) {
88 ret = chdir(home);
89 }
90
91 if (!notify_had_init) {
92 notify_init(_("Brisk Menu Launcher"));
93 notify_had_init = TRUE;
94 }
95
96 /* Setup the action group and hand it to the mate panel */
97 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
98 group = gtk_action_group_new("Brisk Menu Actions");
99 gtk_action_group_set_translation_domain(group, GETTEXT_PACKAGE);
100 gtk_action_group_add_actions(group, brisk_actions, G_N_ELEMENTS(brisk_actions), applet);
101 mate_panel_applet_setup_menu(applet, BRISK_MENU_XML, group);
102 G_GNUC_END_IGNORE_DEPRECATIONS
103
104 g_set_application_name(_("Brisk Menu Launcher"));
105 gtk_widget_show(GTK_WIDGET(applet));
106 return TRUE;
107 }
108
109 MATE_PANEL_APPLET_OUT_PROCESS_FACTORY("BriskMenuFactory", BRISK_TYPE_MENU_APPLET, "BriskMenu",
110 brisk_menu_applet_factory, NULL)
111
112 /*
113 * Editor modelines - https://www.wireshark.org/tools/modelines.html
114 *
115 * Local variables:
116 * c-basic-offset: 8
117 * tab-width: 8
118 * indent-tabs-mode: nil
119 * End:
120 *
121 * vi: set shiftwidth=8 tabstop=8 expandtab:
122 * :indentSize=8:tabSize=8:noTabs=true:
123 */
124