[gnome-applets/wip/segeiger/type-changed: 54/54] draft for reacting to monitor-geometry changed



commit fc94f6cfa7d17af4672755456bd86eafeb05086e
Author: Sebastian Geiger <sbastig gmx net>
Date:   Mon Feb 8 01:34:24 2016 +0100

    draft for reacting to monitor-geometry changed

 windowpicker/src/task-item.c |   56 +++++++++++++++++++++++
 windowpicker/src/task-item.h |    3 +
 windowpicker/src/task-list.c |  103 ++++++++++++++++++++++++++++++++---------
 3 files changed, 139 insertions(+), 23 deletions(-)
---
diff --git a/windowpicker/src/task-item.c b/windowpicker/src/task-item.c
index ca178aa..54e0b85 100644
--- a/windowpicker/src/task-item.c
+++ b/windowpicker/src/task-item.c
@@ -43,11 +43,13 @@ struct _TaskItemPrivate {
     GTimeVal     urgent_time;
     guint        blink_timer;
     gboolean     mouse_over;
+    gint         monitor;
     WpApplet    *windowPickerApplet;
 };
 
 enum {
     TASK_ITEM_CLOSED_SIGNAL,
+    TASK_ITEM_MONITOR_CHANGED,
     LAST_SIGNAL
 };
 
@@ -506,9 +508,45 @@ on_window_type_changed (WnckWindow *window,
                                                 G_CALLBACK (on_window_state_changed), item);
           g_signal_emit (G_OBJECT (item),
                          task_item_signals[TASK_ITEM_CLOSED_SIGNAL], 0);
+
+          gtk_widget_destroy (GTK_WIDGET (item));
       }
 }
 
+gint get_window_monitor (WnckWindow *window)
+{
+    gint x, y, w, h;
+    gint window_monitor;
+    GdkScreen *gdk_screen;
+
+    wnck_window_get_geometry (window, &x, &y, &w, &h);
+
+    gdk_screen = gtk_widget_get_screen (GTK_WIDGET (window));
+    window_monitor = gdk_screen_get_monitor_at_point (gdk_screen,
+                                                      x + w / 2,
+                                                      y + h / 2);
+    return window_monitor;
+}
+
+static void
+on_window_geometry_changed (WnckWindow *window,
+                            TaskItem   *item)
+{
+    g_message ("window geometry changed");
+    gint old_monitor;
+    gint window_monitor;
+
+    window_monitor = get_window_monitor (window);
+
+    old_monitor = item->priv->monitor;
+    if (old_monitor != window_monitor)
+    {
+        item->priv->monitor = window_monitor;
+        g_signal_emit (item, task_item_signals[TASK_ITEM_MONITOR_CHANGED], 0,
+                       old_monitor);
+    }
+}
+
 
 static void on_screen_active_window_changed (
     WnckScreen    *screen,
@@ -571,6 +609,8 @@ static void on_screen_window_closed (
             G_CALLBACK (on_window_type_changed), item);
         g_signal_emit (G_OBJECT (item),
             task_item_signals[TASK_ITEM_CLOSED_SIGNAL], 0);
+
+        gtk_widget_destroy (GTK_WIDGET (item));
     }
 }
 
@@ -810,6 +850,14 @@ static void task_item_class_init (TaskItemClass *klass) {
         G_STRUCT_OFFSET (TaskItemClass, itemclosed),
         NULL, NULL,
         g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+    task_item_signals [TASK_ITEM_MONITOR_CHANGED] =
+        g_signal_new ("monitor-changed",
+        TASK_TYPE_ITEM,
+        G_SIGNAL_RUN_LAST,
+        G_STRUCT_OFFSET (TaskItemClass, monitor_changed),
+        g_signal_accumulator_true_handled, NULL, NULL, G_TYPE_BOOLEAN,
+        1, G_TYPE_INT);
 }
 
 static void task_item_init (TaskItem *item) {
@@ -838,6 +886,7 @@ GtkWidget *task_item_new (WpApplet* windowPickerApplet, WnckWindow *window) {
     screen = wnck_window_get_screen (window);
     priv->screen = screen;
     priv->windowPickerApplet = windowPickerApplet;
+    priv->monitor = get_window_monitor (window);
 
     /** Drag and Drop code
      * This item can be both the target and the source of a drag and drop
@@ -899,6 +948,8 @@ GtkWidget *task_item_new (WpApplet* windowPickerApplet, WnckWindow *window) {
         G_CALLBACK (on_window_icon_changed), item);
     g_signal_connect (window, "type-changed",
         G_CALLBACK (on_window_type_changed), item);
+    g_signal_connect (window, "geometry-changed",
+        G_CALLBACK (on_window_geometry_changed), item);
     g_signal_connect(item, "draw",
         G_CALLBACK(task_item_draw), windowPickerApplet);
     g_signal_connect (item, "button-release-event",
@@ -917,3 +968,8 @@ GtkWidget *task_item_new (WpApplet* windowPickerApplet, WnckWindow *window) {
     task_item_setup_atk (taskItem);
     return item;
 }
+
+gint task_item_get_monitor (TaskItem *item)
+{
+    return item->priv->monitor;
+}
\ No newline at end of file
diff --git a/windowpicker/src/task-item.h b/windowpicker/src/task-item.h
index dcb9a0e..0ea6b10 100644
--- a/windowpicker/src/task-item.h
+++ b/windowpicker/src/task-item.h
@@ -46,9 +46,12 @@ struct _TaskItem {
 struct _TaskItemClass {
     GtkEventBoxClass   parent_class;
     void (* itemclosed) (TaskItem *item);
+    void (* monitor_changed) (TaskItem *item);
 };
 
 GType task_item_get_type (void) G_GNUC_CONST;
 GtkWidget * task_item_new (WpApplet *windowPickerApplet, WnckWindow *window);
 
+gint        task_item_get_monitor (TaskItem *item);
+
 #endif /* _TASK_ITEM_H_ */
diff --git a/windowpicker/src/task-list.c b/windowpicker/src/task-list.c
index c198415..a360f4e 100644
--- a/windowpicker/src/task-list.c
+++ b/windowpicker/src/task-list.c
@@ -33,36 +33,85 @@ static GSList *task_lists;
 
 G_DEFINE_TYPE_WITH_PRIVATE (TaskList, task_list, GTK_TYPE_BOX);
 
-static void on_task_item_closed (
-    TaskItem *item,
-    TaskList *list)
+
+static gint
+task_list_get_monitor (TaskList *task_list)
 {
-    gtk_container_remove (
-        GTK_CONTAINER (list),
-        GTK_WIDGET (item)
-    );
-    gtk_widget_destroy (GTK_WIDGET (item));
+    GdkScreen *gdk_screen;
+    GdkWindow *gdk_window;
+
+    gdk_window = gtk_widget_get_window (GTK_WIDGET (task_list));
+    gdk_screen = gtk_widget_get_screen (GTK_WIDGET (task_list));
+
+    return gdk_screen_get_monitor_at_window (gdk_screen,
+                                             gdk_window);
 }
 
-static void create_task_item (TaskList   *taskList,
-                              WnckWindow *window)
+static gint
+window_get_monitor (WnckWindow *window)
 {
     GdkScreen *gdk_screen;
-    GdkWindow *gdk_window;
-    gint list_monitor, window_monitor;
     gint x, y, w, h;
 
-    if (g_slist_length (task_lists) > 1) {
-        gdk_window = gtk_widget_get_window (GTK_WIDGET (taskList));
-        gdk_screen = gtk_widget_get_screen (GTK_WIDGET (taskList));
-        list_monitor = gdk_screen_get_monitor_at_window (gdk_screen,
-                                                         gdk_window);
+    gdk_screen = gtk_widget_get_screen (GTK_WIDGET (window));
+
+    wnck_window_get_geometry (window, &x, &y, &w, &h);
+
+    return gdk_screen_get_monitor_at_point (gdk_screen,
+                                            x + w / 2,
+                                            y + h / 2);
+}
+
+static TaskList *
+task_lists_get_list_for_monitor (gint monitor)
+{
+    guint i;
+    TaskList *list;
+
+    for (i = 0; i < g_slist_length (task_lists); i++)
+    {
+        list = g_slist_nth_data (task_lists, i);
+        if (task_list_get_monitor (list) == monitor)
+            return list;
+    }
+
+    return g_slist_nth_data (task_lists, 0);
+}
+
+static void
+on_task_item_monitor_changed_cb (TaskItem *item,
+                                 gint      old_monitor,
+                                 TaskList *current_list)
+{
+    gint monitor;
+    gint list_monitor;
+    TaskList *list;
+
+    g_message ("on_task_item_monitor_changed");
+
+    monitor = task_item_get_monitor (item);
+    list_monitor = task_list_get_monitor (current_list);
+
+    if (monitor != list_monitor)
+    {
+        list = task_lists_get_list_for_monitor (monitor);
+        //2. remove item from current_list
+        //3. add item to list
+    }
+
+    // some things to consider:
+    // What if two task lists are on the same monitor?
+}
+
+static void create_task_item (TaskList   *taskList,
+                              WnckWindow *window)
+{
+    gint list_monitor, window_monitor;
 
-        wnck_window_get_geometry (window, &x, &y, &w, &h);
 
-        window_monitor = gdk_screen_get_monitor_at_point (gdk_screen,
-                                                          x + w / 2,
-                                                          y + h / 2);
+    if (g_slist_length (task_lists) > 1) {
+        list_monitor = task_list_get_monitor (taskList);
+        window_monitor = window_get_monitor (window);
 
         if (list_monitor != window_monitor)
             return;
@@ -74,8 +123,16 @@ static void create_task_item (TaskList   *taskList,
     if (item) {
         //we add items dynamically to the end of the list
         gtk_container_add (GTK_CONTAINER(taskList), item);
-        g_signal_connect (TASK_ITEM (item), "task-item-closed",
-                          G_CALLBACK (on_task_item_closed), taskList);
+
+        g_message ("adding item to list: %p", item);
+        // the ALT+F2 dialog seems to appear twice for a brief second when the
+        // dialog is being closed. I need to verify if the gtk_widget_destroy
+        // change is causing this.
+
+        g_signal_connect (TASK_ITEM (item), "monitor-changed",
+                          G_CALLBACK (on_task_item_monitor_changed_cb),
+                          taskList);
+
     }
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]