Enlightenment CVS committal

Author  : atmosphere
Project : misc
Module  : engage

Dir     : misc/engage/src


Modified Files:
        engage.h icon.c wm.c 


Log Message:
icon.c
------
o only intercept resize when we set the icon->pic as a type image
o move icons off visible area before showing
o added code to handle the new edje signals engage,window,raise,[next|prev]

wm.c
----
o added two Evas_Hashes
 -clients: win id -> OD_Window mapping
 -clients_current: window class -> OD_Window mapping
o od_wm_window_[next|prev]_by_window_class_get(const char*)
o rewrote od_sync_clients
o hushed a few compiler warnings for ecore_x_window_prop_property_get
o added od_wm_current_window_by_class_fix, a Evas_Hash foreach function used 
to delete the "current" window, from the hashes if it disappears/closes
o fixed some leaking memory in od_wm_ignored

To test new features 
get http://www.atmos.org/files/creepy_engage-0.1.5.tar.gz
read the README to find out what buttons do what


===================================================================
RCS file: /cvsroot/enlightenment/misc/engage/src/engage.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- engage.h    17 Apr 2004 22:00:29 -0000      1.9
+++ engage.h    23 Apr 2004 23:33:15 -0000      1.10
@@ -66,6 +66,8 @@
 char           *od_wm_get_title(Ecore_X_Window win);    // ditto
 bool            od_wm_iconified(Ecore_X_Window win);
 void            od_wm_activate_window(Ecore_X_Window win);
+OD_Window      *od_wm_window_next_by_window_class_get(const char *);
+OD_Window      *od_wm_window_prev_by_window_class_get(const char *);
 
 struct _OD_Options {
   int             width, height;
===================================================================
RCS file: /cvsroot/enlightenment/misc/engage/src/icon.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -3 -r1.22 -r1.23
--- icon.c      22 Apr 2004 20:22:09 -0000      1.22
+++ icon.c      23 Apr 2004 23:33:16 -0000      1.23
@@ -106,7 +106,7 @@
   Pixmap          pmap, mask;
   Evas_Object    *obj = NULL;
 
-  if (!strcmp(evas_object_type_get(icon->pic), "edje"))
+  if (icon->pic && !strcmp(evas_object_type_get(icon->pic), "edje"))
     return;
 
   dsp = ecore_x_display_get();
@@ -178,11 +178,11 @@
   OD_Icon        *ret = (OD_Icon *) malloc(sizeof(OD_Icon));
   char            path[PATH_MAX];
 
-  Evas_Object    *icon   = NULL;
+  Evas_Object    *icon = NULL;
   Evas_Object    *pic = NULL;
   Evas_Object    *tt_txt = NULL;
   Evas_Object    *tt_shd = NULL;
-  
+
   memset(ret, 0, sizeof(OD_Icon));
   ret->name = strdup(name);
   icon = ret->icon = edje_object_add(evas);
@@ -227,13 +227,15 @@
       evas_object_image_alpha_set(pic, 1);
       evas_object_image_smooth_scale_set(pic, 1);
       evas_object_pass_events_set(pic, 1);
+      evas_object_intercept_resize_callback_add(pic,
+                                                od_object_resize_intercept_cb,
+                                                NULL);
     }
     ret->pic = pic;
     evas_object_layer_set(pic, 100);
+    evas_object_move(pic, -50, -50);
+    evas_object_resize(pic, 32, 32);
     evas_object_show(pic);
-    evas_object_intercept_resize_callback_add(pic,
-                                              od_object_resize_intercept_cb,
-                                              NULL);
     if (edje_object_part_exists(icon, "EngageIcon")) {
       edje_object_part_swallow(icon, "EngageIcon", pic);
     } else {
@@ -512,10 +514,6 @@
           OD_Window      *win = (OD_Window *) l->data;
 
           if (win->applnk == icon && !win->minwin) {
-#if 0
-            clients = evas_list_remove(clients, win);
-            clients = evas_list_append(clients, win);
-#endif
             od_wm_deactivate_window(win->id);
             break;
           }
@@ -550,9 +548,10 @@
 od_icon_edje_win_raise_cb(void *data, Evas_Object * obj, const char *emission, const
                           char *source)
 {
-  pid_t           pid;
+  const char     *winclass = NULL;
   Evas_List      *l = NULL;
   OD_Icon        *icon = NULL;
+  OD_Window      *win = NULL;
 
   if ((icon = (OD_Icon *) data)) {
     if (!strcmp(emission, "engage,window,raise")) {
@@ -561,15 +560,13 @@
       case docked_icon:
       case minimised_window:
         for (l = clients; l; l = l->next) {
-          OD_Window      *win = (OD_Window *) l->data;
+          win = (OD_Window *) l->data;
 
           if (win->minwin == icon || win->applnk == icon) {
-            od_wm_activate_window(win->id);
-            /* FIXME : Maintain order
-             * clients = evas_list_remove(clients, win);
-             * clients = evas_list_append(clients, win);
-             */
-            break;
+            if (od_wm_iconified(win->id)) {
+              od_wm_activate_window(win->id);
+              break;
+            }
           }
         }
         break;
@@ -578,7 +575,7 @@
       }
     } else if (!strcmp(emission, "engage,window,raise,all")) {
       for (l = clients; l; l = l->next) {
-        OD_Window      *win = (OD_Window *) l->data;
+        win = (OD_Window *) l->data;
 
         if (win->minwin == icon || win->applnk == icon) {
           od_wm_activate_window(win->id);
@@ -586,6 +583,38 @@
                                             ECORE_X_WINDOW_STATE_ICONIFIED, 0);
         }
       }
+    } else if (!strcmp(emission, "engage,window,raise,next")) {
+      switch (icon->type) {
+      case application_link:
+      case docked_icon:
+        if (icon->data.applnk.winclass) {
+          winclass = icon->data.applnk.winclass;
+          if ((win = od_wm_window_next_by_window_class_get(winclass))) {
+            od_wm_activate_window(win->id);
+          }
+        }
+        break;
+      case minimised_window:
+        break;
+      default:
+        break;
+      }
+    } else if (!strcmp(emission, "engage,window,raise,prev")) {
+      switch (icon->type) {
+      case application_link:
+      case docked_icon:
+        if (icon->data.applnk.winclass) {
+          winclass = icon->data.applnk.winclass;
+          if ((win = od_wm_window_prev_by_window_class_get(winclass))) {
+            od_wm_activate_window(win->id);
+          }
+        }
+        break;
+      case minimised_window:
+        break;
+      default:
+        break;
+      }
     }
     fprintf(stderr, "Raise got %s from %s\n", emission, icon->name);
   }
===================================================================
RCS file: /cvsroot/enlightenment/misc/engage/src/wm.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- wm.c        22 Apr 2004 17:56:15 -0000      1.7
+++ wm.c        23 Apr 2004 23:33:16 -0000      1.8
@@ -7,13 +7,142 @@
 #include "dmalloc.h"
 #endif
 
+/**
+ * A list of all the X Window clients, data is type OD_Window *
+ */
 Evas_List      *clients = NULL;
 
+/**
+ * A hash of all the X Window clients, window id -> OD_Window* mapping
+ */
+static Evas_Hash *clients_hash = NULL;
+
+/**
+ * A hash of the "current" window for the window class, 
+ * window class -> OD_Window* mapping
+ */
+static Evas_Hash *clients_current = NULL;
+
 static int      od_sync_clients(void *data);
 static int      od_window_id_comp(const void *a, const void *b);
 static Ecore_X_Window *od_wm_get_clients(int *size);
 static bool     od_wm_ignored(Ecore_X_Window win);
 
+OD_Window      *
+od_wm_window_next_by_window_class_get(const char *name)
+{
+  Evas_List      *l = NULL;
+  Evas_List      *tmp = NULL;
+  OD_Window      *win = NULL;
+  OD_Window      *result = NULL;
+  OD_Window      *current = NULL;
+
+#if 0
+  printf("trying to find %s\n", name);
+#endif
+  if ((current = evas_hash_find(clients_current, name))) {
+    clients_current = evas_hash_del(clients_current, name, current);
+    for (l = clients; l; l = l->next) {
+      if ((win = l->data)) {
+        if (od_wm_iconified(win->id))
+          continue;
+        if (win->applnk && win->applnk->data.applnk.winclass) {
+          if (!strcmp(name, win->applnk->data.applnk.winclass)) {
+            tmp = evas_list_append(tmp, win);
+          }
+        }
+      }
+    }
+    for (l = tmp; l; l = l->next) {
+#if 0
+      fprintf(stderr, "%8x %8x\n", ((OD_Window *) l->data)->id, current->id);
+#endif
+      if ((l->data == current) && (l->next)) {
+        result = l->next->data;
+      }
+    }
+    if (!result && tmp)
+      result = tmp->data;
+    evas_list_free(tmp);
+  } else {
+    for (l = clients; l; l = l->next) {
+      if ((win = l->data)) {
+        if (od_wm_iconified(win->id))
+          continue;
+        if (win->applnk && win->applnk->data.applnk.winclass) {
+          if (!strcmp(name, win->applnk->data.applnk.winclass)) {
+            result = win;
+#if 0
+            fprintf(stderr, "%s(%8x)\n", name, win->id);
+#endif
+            break;
+          }
+        }
+      }
+    }
+  }
+  if (result) {
+    clients_current = evas_hash_add(clients_current, name, result);
+  }
+  return (result);
+}
+
+OD_Window      *
+od_wm_window_prev_by_window_class_get(const char *name)
+{
+  Evas_List      *l = NULL;
+  Evas_List      *tmp = NULL;
+  OD_Window      *win = NULL;
+  OD_Window      *result = NULL;
+  OD_Window      *current = NULL;
+
+  if ((current = evas_hash_find(clients_current, name))) {
+    clients_current = evas_hash_del(clients_current, name, current);
+    for (l = clients; l; l = l->next) {
+      if ((win = l->data)) {
+        if (od_wm_iconified(win->id))
+          continue;
+        if (win->applnk && win->applnk->data.applnk.winclass) {
+          if (!strcmp(name, win->applnk->data.applnk.winclass)) {
+            tmp = evas_list_append(tmp, win);
+          }
+        }
+      }
+    }
+    for (l = tmp; l; l = l->next) {
+#if 0
+      fprintf(stderr, "%8x %8x\n", ((OD_Window *) l->data)->id, current->id);
+#endif
+      if ((l->data == current) && (l->prev)) {
+        result = l->prev->data;
+      }
+    }
+    if (!result && tmp && tmp->last)
+      result = tmp->last->data;
+    evas_list_free(tmp);
+  } else {
+    for (l = clients; l; l = l->next) {
+      if ((win = l->data)) {
+        if (win->applnk && win->applnk->data.applnk.winclass) {
+          if (od_wm_iconified(win->id))
+            continue;
+          if (!strcmp(name, win->applnk->data.applnk.winclass)) {
+            result = win;
+#if 0
+            fprintf(stderr, "%s(%8x)\n", name, win->id);
+#endif
+            break;
+          }
+        }
+      }
+    }
+  }
+  if (result) {
+    clients_current = evas_hash_add(clients_current, name, result);
+  }
+  return (result);
+}
+
 char           *
 od_wm_get_winclass(Ecore_X_Window win)
 {
@@ -45,8 +174,8 @@
   Atom           *atom;
 
   if (ecore_x_window_prop_property_get(window, ecore_x_atom_get("WM_STATE"),
-                                       ecore_x_atom_get("WM_STATE"), 32, &atom,
-                                       &size)) {
+                                       ecore_x_atom_get("WM_STATE"), 32,
+                                       (unsigned char **) &atom, &size)) {
     bool            ret = (*atom == IconicState);
 
     free(atom);
@@ -54,7 +183,8 @@
   }
 
   if (ecore_x_window_prop_property_get
-      (window, ecore_x_atom_get("_NET_WM_STATE"), XA_ATOM, 32, &atom, &size)) {
+      (window, ecore_x_atom_get("_NET_WM_STATE"), XA_ATOM, 32,
+       (unsigned char **) &atom, &size)) {
     int             i;
     bool            hidden = false, shaded = false;
 
@@ -76,147 +206,139 @@
 od_dock_icons_update_begin()
 {
   ecore_timer_add(1.0, od_sync_clients, NULL);
+}
 
+Evas_Bool
+od_wm_current_window_by_class_fix(Evas_Hash * hash, const char *key,
+                                  void *data, void *fdata)
+{
+  if (data == fdata) {
+    hash = evas_hash_del(hash, key, data);
+    return (0);
+  }
+  return (1);
 }
 
 int
 od_sync_clients(void *data)
 {
-  Evas_List      *current = clients;
+  int             num_clients;
+  char           *title = NULL;
+  char           *winclass = NULL;
+  char            buf[32];
+  OD_Window      *owd = NULL;
+  OD_Window      *owd_tmp = NULL;
+  Evas_List      *dirty = NULL;
   Evas_List      *fresh = NULL;
-
-  {
-    int             num_clients;
-    Ecore_X_Window *windows = od_wm_get_clients(&num_clients);
-
-    qsort(windows, num_clients, sizeof(Ecore_X_Window), od_window_id_comp);
-    Ecore_X_Window *win = windows;
-
-    while (num_clients--) {
-      OD_Window      *owd = (OD_Window *) malloc(sizeof(OD_Window));
-
-      owd->id = *win;
-      owd->applnk = NULL;
-      owd->minwin = NULL;
-      fresh = evas_list_append(fresh, owd);
-      win++;
+  Evas_List      *item = NULL;
+  Evas_List      *to_free = NULL;
+  Ecore_X_Window *win = NULL;
+  Ecore_X_Window *windows = NULL;
+
+  dirty = clients;
+  clients = NULL;
+  windows = od_wm_get_clients(&num_clients);
+  qsort(windows, num_clients, sizeof(Ecore_X_Window), od_window_id_comp);
+  win = windows;
+
+  while (num_clients--) {
+    owd = NULL;
+    if (!od_wm_ignored(*win)) {
+      snprintf(buf, 32, "%8x", *win);
+      if ((owd = evas_hash_find(clients_hash, buf))) {
+        dirty = evas_list_remove(dirty, owd);
+        if (!owd->minwin && od_wm_iconified(owd->id)) {
+          owd->minwin = od_icon_new_minwin(owd->id);
+          od_dock_add_minwin(owd->minwin);
+        } else if (owd->minwin && !od_wm_iconified(owd->id)) {
+          od_dock_del_icon(owd->minwin);
+          owd->minwin = NULL;
+        } else if (owd->minwin) {
+          title = od_wm_get_title(owd->id);
+          if (strcmp(title, owd->minwin->name) != 0)
+            od_icon_name_change(owd->minwin, title);
+          free(title);
+        }
+      } else {
+        fprintf(stderr, "New %8x window id\n", *win);
+        owd = (OD_Window *) malloc(sizeof(OD_Window));
+        memset(owd, 0, sizeof(OD_Window));
+        owd->id = *win;
+        clients_hash = evas_hash_add(clients_hash, buf, owd);
+        fresh = evas_list_append(fresh, owd);
+      }
+      clients = evas_list_append(clients, owd);
     }
-    free(windows);
+    win++;
   }
+  free(windows);
 
-  Evas_List      *pcurrent = current;
-  Evas_List      *pfresh = fresh;
-
-  while (pcurrent || pfresh) {
-    OD_Window      *wcurrent = (OD_Window *) (pcurrent ? pcurrent->data : NULL);
-    OD_Window      *wfresh = (OD_Window *) (pfresh ? pfresh->data : NULL);
-
-    if (wcurrent && (!wfresh || wcurrent->id < wfresh->id)) {   // wcurrent 
disappeared
-#if 0
-      fprintf(stderr, "window disappeared: id=0x%.8x\n", wcurrent->id);
-#endif
-      if (wcurrent->minwin)
-        od_dock_del_icon(wcurrent->minwin);
-      if (wcurrent->applnk) {
-        if (wcurrent->applnk->data.applnk.count == 0) {
-          fprintf(stderr, "eek! applnk %s already has no windows\n",
-                  wcurrent->applnk->name);
-          exit(EXIT_FAILURE);
-        }
-        wcurrent->applnk->data.applnk.count--;
-        if (wcurrent->applnk->data.applnk.count == 0) {
-          od_icon_arrow_hide(wcurrent->applnk);
-          if (wcurrent->applnk->data.applnk.command[0] == '\0')
-            od_dock_del_icon(wcurrent->applnk);
+  /* pending windows that aren't present anymore */
+  to_free = dirty;
+  while (dirty) {
+    if (dirty->data) {
+      owd = dirty->data;
+      snprintf(buf, 32, "%8x", owd->id);
+      fprintf(stderr, "%s no longer exists\n", buf);
+
+      evas_hash_foreach(clients_current, od_wm_current_window_by_class_fix,
+                        owd);
+      clients_hash = evas_hash_del(clients_hash, buf, owd);
+      if (owd->minwin)
+        od_dock_del_icon(owd->minwin);
+      if ((owd->applnk) && (owd->applnk->data.applnk.count > 0)) {
+        owd->applnk->data.applnk.count--;
+        if (owd->applnk->data.applnk.count == 0) {
+          od_icon_arrow_hide(owd->applnk);
+          if (owd->applnk->data.applnk.command[0] == '\0') {
+            od_dock_del_icon(owd->applnk);
+            free(owd);
+          }
         }
       }
+    }
+    dirty = dirty->next;
+  }
+  to_free = evas_list_free(to_free);
 
-      pcurrent = pcurrent->next;
-    } else if (wcurrent && wfresh && wcurrent->id == wfresh->id) {      // update info
-      wfresh->applnk = wcurrent->applnk;
-      wfresh->minwin = wcurrent->minwin;
-      char           *title = NULL;
-
-      if (!wfresh->minwin && od_wm_iconified(wfresh->id)) {
-        wfresh->minwin = od_icon_new_minwin(wfresh->id);
-        od_dock_add_minwin(wfresh->minwin);
-      } else if (wfresh->minwin && !od_wm_iconified(wfresh->id)) {
-        od_dock_del_icon(wfresh->minwin);
-        wfresh->minwin = NULL;
-      } else if (wfresh->minwin &&
-                 strcmp((title =
-                         od_wm_get_title(wcurrent->id)),
-                        wfresh->minwin->name) != 0) {
-        od_icon_name_change(wfresh->minwin, title);
-        if (title)
-          free(title);
-      }
-
-      pcurrent = pcurrent->next;
-      pfresh = pfresh->next;
-    } else if (wfresh && (!wcurrent || wcurrent->id > wfresh->id)) {    // new 
window: wfresh
-      char           *title = od_wm_get_title(wfresh->id);
-      char           *winclass = od_wm_get_winclass(wfresh->id);
-
-#if 0
-      fprintf(stderr,
-              "window appeared: id=0x%.8x, name=\"%s\", winclass=\"%s\"\n",
-              wfresh->id, title, winclass);
-#endif
-
-      if (!od_wm_ignored(wfresh->id)) {
-        {
-          wfresh->applnk = NULL;
-          Evas_List      *item = dock.applnks;
-
-          while (item) {
-            OD_Icon        *applnk = (OD_Icon *) item->data;
-
-            if (strcmp(applnk->data.applnk.winclass, winclass) == 0) {
-              wfresh->applnk = applnk;
-              break;
-            }
-            item = item->next;
-          }
+  to_free = fresh;
+  while (fresh) {
+    if (fresh->data) {
+      owd = fresh->data;
+      title = od_wm_get_title(owd->id);
+      winclass = od_wm_get_winclass(owd->id);
+      item = dock.applnks;
+
+      while (item) {
+        OD_Icon        *applnk = (OD_Icon *) item->data;
+
+        if (strcmp(applnk->data.applnk.winclass, winclass) == 0) {
+          owd->applnk = applnk;
+          break;
         }
-        if (!wfresh->applnk) {
-          wfresh->applnk = od_icon_new_applnk("", winclass);
-          od_dock_add_applnk(wfresh->applnk);
-        }
-        wfresh->applnk->data.applnk.count++;
-        od_icon_arrow_show(wfresh->applnk);
-
-        if (od_wm_iconified(wfresh->id)) {
-          wfresh->minwin = od_icon_new_minwin(wfresh->id);
-          od_dock_add_minwin(wfresh->minwin);
-        } else
-          wfresh->minwin = NULL;
+        item = item->next;
+      }
+      if (!owd->applnk) {
+        owd->applnk = od_icon_new_applnk("", winclass);
+        od_dock_add_applnk(owd->applnk);
+      }
+      owd->applnk->data.applnk.count++;
+      od_icon_arrow_show(owd->applnk);
+      if (od_wm_iconified(owd->id)) {
+        owd->minwin = od_icon_new_minwin(owd->id);
+        od_dock_add_minwin(owd->minwin);
+      }
 #ifdef HAVE_IMLIB
-        if (options.grab_app_icons)
-          od_icon_grab(wfresh->applnk, wfresh->id);
+      if (options.grab_app_icons)
+        od_icon_grab(owd->applnk, owd->id);
 #endif
-      }
-
       free(title);
       free(winclass);
-      pfresh = pfresh->next;
-    } else {
-      fprintf(stderr, "eeek!!!\n");
-      exit(EXIT_FAILURE);
-    }
-  }
-
-  // swap the two lists
-  {
-    clients = fresh;
-    Evas_List      *item = current;
-
-    while (item) {
-      free(item->data);
-      item = evas_list_next(item);
     }
-    evas_list_free(current);
+    fresh->data = NULL;
+    fresh = fresh->next;
   }
+  to_free = evas_list_free(to_free);
   return 1;                     // keep going
 }
 
@@ -232,10 +354,11 @@
   Ecore_X_Window *win_list;
 
   if (!ecore_x_window_prop_property_get(0, ecore_x_atom_get("_NET_CLIENT_LIST"),
-                                        XA_WINDOW, 32, &win_list, size)) {
+                                        XA_WINDOW, 32,
+                                        (unsigned char **) &win_list, size)) {
     if (!ecore_x_window_prop_property_get
-        (0, ecore_x_atom_get("_WIN_CLIENT_LIST"), XA_CARDINAL, 32, &win_list,
-         size)) {
+        (0, ecore_x_atom_get("_WIN_CLIENT_LIST"), XA_CARDINAL, 32,
+         (unsigned char **) &win_list, size)) {
       *size = 0;
       return NULL;
     }
@@ -246,19 +369,22 @@
 bool
 od_wm_ignored(Ecore_X_Window win)
 {
+  bool            result = false;
   static char    *ignore[] = { "engage", "kicker", "", NULL };
   char          **cur = ignore;
   char           *winclass = od_wm_get_winclass(win);
 
   while (*cur) {
     if (strcmp(*cur, winclass) == 0)
-      return true;
+      result = true;
     cur++;
   }
 
   if (ecore_x_window_prop_state_isset(win, ECORE_X_WINDOW_STATE_SKIP_TASKBAR))
-    return true;
-  return false;
+    result = true;
+  if (winclass)
+    free(winclass);
+  return result;
 }
 
 void




-------------------------------------------------------
This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
For a limited time only, get FREE Ground shipping on all orders of $35
or more. Hurry up and shop folks, this offer expires April 30th!
http://www.thinkgeek.com/freeshipping/?cpg=12297
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to