xfwm4: Patch for multiple tasks in task switcher

Matt Hall matthew.hall at duke.edu
Tue Aug 19 07:41:42 CEST 2003


Hey guys...

I modified xfwm4 so that when you switch between tasks (alt-tab as per
xfwm4 default) it will list all the current tasks in the popup box
instead of the current one.  Although xfwm4 displays the outlines of
each window while iterating through the list, it can still be somewhat
confusing to determine which task you're switching to if tasks have
similar names.  With this patch, all the tasks are displayed, and as you
iterate through them, the currently selected one is highlighted, making
things a bit clearer.  Let me know if you guys like it.  The patch is
below (and was made by diffing against cvs from the rc2 tag).

-matt

------------ cut here for patch --------------

Index: client.c
===================================================================
RCS file: /cvsroot/xfce/xfce-devel/xfwm4/src/client.c,v
retrieving revision 1.251
diff -c -r1.251 client.c
*** client.c	20 Jul 2003 17:11:41 -0000	1.251
--- client.c	17 Aug 2003 22:50:27 -0000
***************
*** 3185,3190 ****
--- 3185,3203 ----
      return okay;
  }
  
+ gboolean
+ clientIsGoodWindow(Client *c, int cycle_range)
+ {
+     TRACE ("entering clientIsGoodWindow");
+ 
+     if (!c)
+     {
+         return FALSE;
+     }
+ 
+    return ((c->type != WINDOW_SPLASHSCREEN) && (c->type !=
WINDOW_DESKTOP) && (clientSelectMask (c, cycle_range)));
+ }
+ 
  Client *
  clientGetNext (Client * c, int mask)
  {
***************
*** 5150,5156 ****
                  {
                      /* Redraw frame draw */
                      clientDrawOutline (passdata->c);
!                     tabwinSetLabel (passdata->tabwin, passdata->c->name);
                  }
                  else
                  {
--- 5163,5169 ----
                  {
                      /* Redraw frame draw */
                      clientDrawOutline (passdata->c);
!                     tabwinUpdateLabel (passdata->tabwin, passdata->c);
                  }
                  else
                  {
***************
*** 5225,5231 ****
      passdata.c = clientGetNext (c, passdata.cycle_range);
      if (passdata.c)
      {
!         passdata.tabwin = tabwinCreate (passdata.c->name);
          TRACE ("entering cycle loop");
          /* Draw frame draw */
          clientDrawOutline (passdata.c);
--- 5238,5244 ----
      passdata.c = clientGetNext (c, passdata.cycle_range);
      if (passdata.c)
      {
!         passdata.tabwin = tabwinCreate (passdata.c, passdata.cycle_range);
          TRACE ("entering cycle loop");
          /* Draw frame draw */
          clientDrawOutline (passdata.c);
Index: client.h
===================================================================
RCS file: /cvsroot/xfce/xfce-devel/xfwm4/src/client.h,v
retrieving revision 1.76
diff -c -r1.76 client.h
*** client.h	30 Jun 2003 22:24:03 -0000	1.76
--- client.h	17 Aug 2003 22:50:28 -0000
***************
*** 222,227 ****
--- 222,228 ----
  
  Client *clientGetTransient (Client *);
  gboolean clientIsTransient (Client *);
+ gboolean clientIsGoodWindow(Client *, int);
  gboolean clientSameGroup (Client *, Client *);
  gboolean clientIsTransientFor (Client *, Client *);
  gboolean clientIsTransientForGroup (Client *);
Index: tabwin.h
===================================================================
RCS file: /cvsroot/xfce/xfce-devel/xfwm4/src/tabwin.h,v
retrieving revision 1.8
diff -c -r1.8 tabwin.h
*** tabwin.h	16 May 2003 19:20:19 -0000	1.8
--- tabwin.h	17 Aug 2003 22:50:28 -0000
***************
*** 28,43 ****
  #include <gdk/gdk.h>
  #include <gdk/gdkx.h>
  #include <gtk/gtk.h>
  
  typedef struct _Tabwin Tabwin;
  struct _Tabwin
  {
      GtkWidget *window;
!     GtkWidget *label;
  };
  
! Tabwin *tabwinCreate (gchar * label);
! void tabwinSetLabel (Tabwin * tabwin, gchar * label);
  void tabwinDestroy (Tabwin * tabwin);
  
  #endif /* INC_TABWIN_H */
--- 28,56 ----
  #include <gdk/gdk.h>
  #include <gdk/gdkx.h>
  #include <gtk/gtk.h>
+ #include "client.h"
+ 
+ typedef struct _Tabitem Tabitem;
+ struct _Tabitem
+ {
+    GtkWidget *labelcontainer;
+    GdkColor   labelcontainerdef;
+    GtkWidget *label;
+    GdkColor   labeldef;
+    Client    *client;
+    int        cycle_range;
+ };
  
  typedef struct _Tabwin Tabwin;
  struct _Tabwin
  {
      GtkWidget *window;
!     GSList *tabitems;
  };
  
! Tabwin *tabwinCreate (Client *c, int cycle_range);
! void tabwinUpdateLabel (Tabwin * tabwin, Client *c);
! static void updateLabel_foreach(gpointer data, gpointer user_data);
  void tabwinDestroy (Tabwin * tabwin);
  
  #endif /* INC_TABWIN_H */
Index: tabwin.c
===================================================================
RCS file: /cvsroot/xfce/xfce-devel/xfwm4/src/tabwin.c,v
retrieving revision 1.11
diff -c -r1.11 tabwin.c
*** tabwin.c	22 May 2003 22:31:46 -0000	1.11
--- tabwin.c	17 Aug 2003 22:50:28 -0000
***************
*** 32,46 ****
  #include "tabwin.h"
  
  Tabwin *
! tabwinCreate (gchar * label)
  {
      static GdkPixbuf *icon = NULL;
      Tabwin *tabwin;
      GtkWidget *frame;
      GtkWidget *vbox;
      GtkWidget *header;
  
      tabwin = g_new (Tabwin, 1);
  
      if (!icon)
      {
--- 32,50 ----
  #include "tabwin.h"
  
  Tabwin *
! tabwinCreate (Client *client, int cycle_range)
  {
      static GdkPixbuf *icon = NULL;
      Tabwin *tabwin;
+     Tabitem *tabitem;
      GtkWidget *frame;
      GtkWidget *vbox;
      GtkWidget *header;
+     GSList *window;
+     Client *cur, *head;
  
      tabwin = g_new (Tabwin, 1);
+     tabwin->tabitems = NULL;
  
      if (!icon)
      {
***************
*** 82,114 ****
      gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
      gtk_container_add (GTK_CONTAINER (frame), vbox);
  
!     tabwin->label = gtk_label_new ("");
!     if (label)
      {
!         tabwinSetLabel (tabwin, label);
      }
!     gtk_misc_set_alignment (GTK_MISC (tabwin->label), 0.5, 0.5);
!     gtk_widget_show (tabwin->label);
!     gtk_box_pack_start (GTK_BOX (vbox), tabwin->label, FALSE, TRUE, 0);
      gtk_widget_show (tabwin->window);
  
      return tabwin;
  }
  
  void
! tabwinSetLabel (Tabwin * tabwin, gchar * label)
  {
!     g_return_if_fail (tabwin != NULL);
  
!     if (label)
      {
!         gtk_label_set_text (GTK_LABEL (tabwin->label), label);
      }
      else
      {
!         gtk_label_set_text (GTK_LABEL (tabwin->label), "");
      }
-     gtk_widget_queue_draw (tabwin->window);
  }
  
  void
--- 86,160 ----
      gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);
      gtk_container_add (GTK_CONTAINER (frame), vbox);
  
!     /** Get our first window and then skip ahead until we find a
usable window */
!     window = clientGetStackList();
!     while (!clientIsGoodWindow((Client *) window->data, cycle_range))
      {
!         window = g_slist_next(window);
      }
! 
!     /** This is our first usable window,
!         we need to keep track of it to
!         avoid a loop in our circularly
!         linked list
!     */
!     head = (Client *) window->data;
!     cur = head;
! 
!     do
!     {
!         tabitem = g_new (Tabitem, 1);
!         tabitem->labelcontainer = gtk_event_box_new();
!         tabitem->labelcontainerdef =
tabitem->labelcontainer->style->bg[GTK_STATE_NORMAL];
!         tabitem->label = gtk_label_new ((cur->name ? cur->name : ""));
!         tabitem->labeldef = tabitem->label->style->fg[GTK_STATE_NORMAL];
!         tabitem->client = cur;
!         tabitem->cycle_range = cycle_range;
! 
!         if (cur == client)
!         {
!              gtk_widget_modify_bg (tabitem->labelcontainer,
GTK_STATE_NORMAL, &tabitem->labelcontainer->style->bg[GTK_STATE_SELECTED]);
!              gtk_widget_modify_fg (tabitem->label, GTK_STATE_NORMAL,
&tabitem->label->style->fg[GTK_STATE_SELECTED]);
!         }
! 
!         gtk_misc_set_alignment (GTK_MISC (tabitem->label), 0.5, 0.5);
!         gtk_widget_show (tabitem->label);
!         gtk_container_add (GTK_CONTAINER (tabitem->labelcontainer),
tabitem->label);
!         gtk_widget_show (tabitem->labelcontainer);
!         gtk_box_pack_start (GTK_BOX (vbox), tabitem->labelcontainer,
FALSE, TRUE, 0);
! 
!         tabwin->tabitems = g_slist_append(tabwin->tabitems, tabitem);
! 
!         cur = clientGetNext(cur, cycle_range);
!     } while ((cur) && (cur != head));
! 
      gtk_widget_show (tabwin->window);
  
      return tabwin;
  }
  
  void
! tabwinUpdateLabel(Tabwin *tabwin, Client *client)
  {
!     g_slist_foreach(tabwin->tabitems, updateLabel_foreach, client);
! }
! 
! static void
! updateLabel_foreach(gpointer data, gpointer user_data)
! {
!     Tabitem *tabitem = (Tabitem *) data;
!     Client *client = (Client *) user_data;
  
!     if (tabitem->client == client)
      {
!         gtk_widget_modify_bg (tabitem->labelcontainer,
GTK_STATE_NORMAL, &tabitem->labelcontainer->style->bg[GTK_STATE_SELECTED]);
!         gtk_widget_modify_fg (tabitem->label, GTK_STATE_NORMAL,
&tabitem->label->style->fg[GTK_STATE_SELECTED]);
      }
      else
      {
!         gtk_widget_modify_bg (tabitem->labelcontainer,
GTK_STATE_NORMAL, &tabitem->labelcontainerdef);
!         gtk_widget_modify_fg (tabitem->label, GTK_STATE_NORMAL,
&tabitem->labeldef);
      }
  }
  
  void
***************
*** 117,120 ****
--- 163,167 ----
      g_return_if_fail (tabwin != NULL);
  
      gtk_widget_destroy (tabwin->window);
+     g_slist_free(tabwin->tabitems);
  }




More information about the Xfce4-dev mailing list