summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2015-01-25 03:26:37 +0100
committerJavier <dev.git@javispedro.com>2015-01-25 03:26:37 +0100
commitfd1ad6fba7437f049854720b892fdd033b3c8be3 (patch)
treef60c87efe5e6b60725974672d7878771ada6335f
parenta9c455b0094cfba67db87885079eb566146895c5 (diff)
downloadmdock-fd1ad6fba7437f049854720b892fdd033b3c8be3.tar.gz
mdock-fd1ad6fba7437f049854720b892fdd033b3c8be3.zip
right click on window selector
-rw-r--r--libmdock/mdock-item-menu.c21
-rw-r--r--libmdock/mdock-item-window-selector.c32
2 files changed, 52 insertions, 1 deletions
diff --git a/libmdock/mdock-item-menu.c b/libmdock/mdock-item-menu.c
index 04b3571..6121cdb 100644
--- a/libmdock/mdock-item-menu.c
+++ b/libmdock/mdock-item-menu.c
@@ -38,6 +38,7 @@ struct _MDockItemMenuPrivate
GPtrArray *menu_recent;
GCancellable *recent_fetch;
+ time_t recent_fetch_time;
};
G_DEFINE_TYPE (MDockItemMenu, mdock_item_menu, GTK_TYPE_MENU)
@@ -52,6 +53,8 @@ static GParamSpec *obj_properties[N_PROPERTIES] = { NULL };
#ifdef HAVE_ZEITGEIST
+#define RECENT_FETCH_MIN_INTERVAL 15
+
G_DEFINE_QUARK(mdock-item-menu-file, mdock_item_menu_file)
static void clear_recent_menu(MDockItemMenu *self)
@@ -166,6 +169,7 @@ static void refresh_recent_menu(MDockItemMenu *self)
}
self->priv->recent_fetch = g_cancellable_new();
+ time(&self->priv->recent_fetch_time);
GDesktopAppInfo *appinfo = mdock_item_get_desktop_app_info(self->item);
if (!appinfo) {
@@ -173,6 +177,8 @@ static void refresh_recent_menu(MDockItemMenu *self)
return;
}
+ g_debug("refreshing recent menu");
+
ZeitgeistTimeRange *range = zeitgeist_time_range_new_anytime();
GPtrArray *templs = g_ptr_array_new_full(1, (GDestroyNotify)g_object_unref);
@@ -187,6 +193,19 @@ static void refresh_recent_menu(MDockItemMenu *self)
g_object_unref(range);
g_ptr_array_unref(templs);
}
+
+static gboolean handle_menu_map(MDockItemMenu *self, GdkEventAny *event)
+{
+ time_t now;
+ time(&now);
+
+ if (now - self->priv->recent_fetch_time > RECENT_FETCH_MIN_INTERVAL) {
+ refresh_recent_menu(self);
+ }
+
+ return FALSE;
+}
+
#endif
static void handle_item_pinned(MDockItemMenu *self, GParamSpec *spec, MDockItem *item)
@@ -284,6 +303,8 @@ mdock_item_menu_constructed(GObject *object)
handle_item_pinned(self, NULL, self->item);
#ifdef HAVE_ZEITGEIST
+ g_signal_connect(self, "map-event",
+ G_CALLBACK(handle_menu_map), self);
refresh_recent_menu(self);
#endif
}
diff --git a/libmdock/mdock-item-window-selector.c b/libmdock/mdock-item-window-selector.c
index 7bd0199..2fbf3e7 100644
--- a/libmdock/mdock-item-window-selector.c
+++ b/libmdock/mdock-item-window-selector.c
@@ -48,6 +48,8 @@ enum MDockItemWindowSelectorProperties {
static GParamSpec *obj_properties[N_PROPERTIES] = { NULL };
+G_DEFINE_QUARK(mdock-item-window-selector-menu, mdock_item_window_selector_menu)
+
static GSequenceIter * find_window(MDockItemWindowSelector *self, WnckWindow *window)
{
GSequenceIter *iter = g_sequence_get_begin_iter(self->priv->windows);
@@ -62,13 +64,34 @@ static GSequenceIter * find_window(MDockItemWindowSelector *self, WnckWindow *wi
return NULL;
}
+static gboolean handle_window_button_press(MDockItemWindowSelector *self, GdkEventButton *event, MDockWindow *window)
+{
+ g_debug("window item button press");
+
+ switch (event->button) {
+ case 3:
+ gtk_menu_popup(GTK_MENU(g_object_get_qdata(G_OBJECT(window), mdock_item_window_selector_menu_quark())),
+ NULL, NULL, NULL, NULL,
+ event->button, event->time);
+ break;
+ }
+
+ return TRUE;
+}
+
static gboolean handle_window_button_release(MDockItemWindowSelector *self, GdkEventButton *event, MDockWindow *window)
{
g_debug("window item button release");
switch (event->button) {
case 1:
- wnck_window_activate_transient(window->window, event->time);
+ if (!wnck_window_is_minimized(window->window) &&
+ (wnck_window_is_most_recently_activated(window->window)
+ || wnck_window_transient_is_most_recently_activated(window->window))) {
+ wnck_window_minimize(window->window);
+ } else {
+ wnck_window_activate_transient(window->window, event->time);
+ }
break;
}
@@ -188,9 +211,16 @@ void mdock_item_window_selector_add_window(MDockItemWindowSelector *self, WnckWi
gtk_widget_hide(GTK_WIDGET(self->priv->app_label));
gtk_widget_show(GTK_WIDGET(win));
+ g_signal_connect_object(win, "button-press-event",
+ G_CALLBACK(handle_window_button_press), self,
+ G_CONNECT_SWAPPED);
g_signal_connect_object(win, "button-release-event",
G_CALLBACK(handle_window_button_release), self,
G_CONNECT_SWAPPED);
+
+ g_object_set_qdata_full(G_OBJECT(win), mdock_item_window_selector_menu_quark(),
+ wnck_action_menu_new(window),
+ (GDestroyNotify)gtk_widget_destroy);
}
void mdock_item_window_selector_remove_window(MDockItemWindowSelector *self, WnckWindow *window)