Skip to content

Commit

Permalink
Load the sidebar shortcuts from our default GSettings
Browse files Browse the repository at this point in the history
This will allow vendors to override the shortcuts that appear in the
sidepane of the Brisk Menu. As an example, Solus would add the software
center (solus-sc.desktop) and Ubuntu MATE could likely add their Botique
or even links to documentation.

Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeydoherty committed Jan 1, 2017
1 parent 9f28ba2 commit 2959f67
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ brisk_menu_SOURCES = \
src/launcher.c \
src/menu-grabs.c \
src/menu-keyboard.c \
src/menu-loader.c \
src/menu-private.h \
src/menu-search.c \
src/menu-session.c \
src/menu-settings.c \
src/menu-sort.c \
src/menu-loader.c \
src/menu-window.h \
src/menu-window.c \
src/util.h
Expand Down
19 changes: 9 additions & 10 deletions src/menu-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ static guint source_id = 0;

#define BRISK_RELOAD_TIME 1500

/**
* We can add more here if appropriate.
*/
static gchar *brisk_default_shortcuts[] = {
"matecc.desktop",
};

/**
* Recurse the given directory and any of it's children directories. Add all of
* the directories to the sidebar, and then (TODO) stick "normal" types into the
Expand Down Expand Up @@ -91,6 +84,7 @@ static void brisk_menu_window_build(BriskMenuWindow *self)
{
autofree(MateMenuTreeDirectory) *dir = NULL;
GtkWidget *sep = NULL;
autofree(gstrv) *shortcuts = NULL;

g_message("debug: menu reloaded");

Expand All @@ -117,9 +111,14 @@ static void brisk_menu_window_build(BriskMenuWindow *self)
gtk_widget_show_all(sep);

/* Load the shortcuts up */
size_t n_shortcuts = sizeof(brisk_default_shortcuts) / sizeof(brisk_default_shortcuts[0]);
for (size_t i = 0; i < n_shortcuts; i++) {
brisk_menu_window_add_shortcut(self, brisk_default_shortcuts[i]);
shortcuts = g_settings_get_strv(self->settings, "pinned-shortcuts");
if (!shortcuts) {
return;
}

/* Add from gsettings */
for (guint i = 0; i < g_strv_length(shortcuts); i++) {
brisk_menu_window_add_shortcut(self, shortcuts[i]);
}
brisk_menu_window_set_filters_enabled(self, TRUE);
}
Expand Down
10 changes: 10 additions & 0 deletions src/menu-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ struct _BriskMenuWindow {
GtkWidget *button_lock;
GtkWidget *button_logout;
GtkWidget *button_shutdown;

/* Global settings for all BriskMenu instances */
GSettings *settings;
};

/* Split the implementation across multiple files for ease of maintenance */
Expand Down Expand Up @@ -104,6 +107,9 @@ void brisk_menu_window_configure_grabs(BriskMenuWindow *self);
void brisk_menu_window_setup_session_controls(BriskMenuWindow *self);
gboolean brisk_menu_window_setup_session(BriskMenuWindow *self);

/* Settings */
void brisk_menu_window_init_settings(BriskMenuWindow *self);

DEF_AUTOFREE(GtkWidget, gtk_widget_destroy)
DEF_AUTOFREE(MateMenuTree, matemenu_tree_unref)
DEF_AUTOFREE(MateMenuTreeDirectory, matemenu_tree_item_unref)
Expand All @@ -116,6 +122,10 @@ DEF_AUTOFREE(gchar, g_free)
DEF_AUTOFREE(GdkAppLaunchContext, g_object_unref)
DEF_AUTOFREE(GError, g_error_free)

/* Helper for gsettings */
typedef gchar *gstrv;
DEF_AUTOFREE(gstrv, g_strfreev)

/**
* Convenience function to remove children from a container
*/
Expand Down
36 changes: 36 additions & 0 deletions src/menu-settings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of brisk-menu.
*
* Copyright © 2016 Ikey Doherty <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/

#include "util.h"

#include <stdlib.h>

BRISK_BEGIN_PEDANTIC
#include "menu-private.h"
BRISK_END_PEDANTIC

void brisk_menu_window_init_settings(BriskMenuWindow *self)
{
self->settings = g_settings_new("com.solus-project.brisk-menu");
}

/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 8
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=8 tabstop=8 expandtab:
* :indentSize=8:tabSize=8:noTabs=true:
*/
2 changes: 2 additions & 0 deletions src/menu-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static void brisk_menu_window_dispose(GObject *obj)
g_clear_object(&self->launcher);
g_clear_object(&self->session);
g_clear_object(&self->saver);
g_clear_object(&self->settings);

G_OBJECT_CLASS(brisk_menu_window_parent_class)->dispose(obj);
}
Expand Down Expand Up @@ -96,6 +97,7 @@ static void brisk_menu_window_init(BriskMenuWindow *self)

self->launcher = brisk_menu_launcher_new();
brisk_menu_window_load_css(self);
brisk_menu_window_init_settings(self);

gtk_window_set_decorated(GTK_WINDOW(self), FALSE);
gtk_window_set_type_hint(GTK_WINDOW(self), GDK_WINDOW_TYPE_HINT_POPUP_MENU);
Expand Down

0 comments on commit 2959f67

Please sign in to comment.