Hi there,

I've done a small patch for the pager, it allow the user to drag a desktop from
the pager, and drop it on the pager or on the current desktop. At the drop the
two desktops are switched. By default the button is desactivate.

More exactly, windows move from one desk to the other, and if there is a name
or a specific background setted on one of the desk. e_config is updated and
saved. Dnd across different zones is supported.

I found that useful when it come to sort desktops. I just hope that I'm not
the only one to think that :)

This patch also fix the warning at build time.
Also attached there's two small patch for little checks missing in e_remember.c
and e_zone.c

Any comments is welcome.

lok
Index: e_remember.c
===================================================================
RCS file: /cvs/e/e17/apps/e/src/bin/e_remember.c,v
retrieving revision 1.22
diff -u -r1.22 e_remember.c
--- e_remember.c	4 Jan 2007 10:30:55 -0000	1.22
+++ e_remember.c	20 Feb 2007 22:47:47 -0000
@@ -206,6 +206,7 @@
 EAPI void
 e_remember_update(E_Remember *rem, E_Border *bd)
 {
+   if (!rem) return;
    if (bd->new_client) return;
    if (rem->name) evas_stringshare_del(rem->name);
    if (rem->class) evas_stringshare_del(rem->class);
Index: e_zone.c
===================================================================
RCS file: /cvs/e/e17/apps/e/src/bin/e_zone.c,v
retrieving revision 1.108
diff -u -r1.108 e_zone.c
--- e_zone.c	28 Jan 2007 07:22:50 -0000	1.108
+++ e_zone.c	20 Feb 2007 22:47:29 -0000
@@ -440,8 +440,8 @@
    E_OBJECT_CHECK(zone);
    E_OBJECT_TYPE_CHECK(zone, E_ZONE_TYPE);
    
-   *x_count = zone->desk_x_count;
-   *y_count = zone->desk_y_count;
+   if (x_count) *x_count = zone->desk_x_count;
+   if (y_count) *y_count = zone->desk_y_count;
 }
 
 EAPI void
? pager.patch
Index: e_mod_config.c
===================================================================
RCS file: /cvs/e/e17/apps/e/src/modules/pager/e_mod_config.c,v
retrieving revision 1.27
diff -u -r1.27 e_mod_config.c
--- e_mod_config.c	3 Feb 2007 02:02:49 -0000	1.27
+++ e_mod_config.c	20 Feb 2007 22:50:30 -0000
@@ -5,7 +5,8 @@
 enum _Pager_Grab_Button
 {
    GRAB_BUTTON_DRAG,
-   GRAB_BUTTON_NOPLACE
+   GRAB_BUTTON_NOPLACE,
+   GRAB_BUTTON_DESK
 };
 
 struct _E_Config_Dialog_Data
@@ -15,6 +16,7 @@
    int drag_resist;
    unsigned char btn_drag;
    unsigned char btn_noplace;
+   unsigned char btn_desk;
    int flip_desk;
 
    struct {
@@ -27,6 +29,7 @@
    struct {
       Evas_Object *o_btn1;
       Evas_Object *o_btn2;
+      Evas_Object *o_btn3;
    } gui;
 };
 
@@ -76,6 +79,7 @@
    cfdata->drag_resist = pager_config->drag_resist;
    cfdata->btn_drag = pager_config->btn_drag;
    cfdata->btn_noplace = pager_config->btn_noplace;
+   cfdata->btn_desk = pager_config->btn_desk;
    cfdata->flip_desk = pager_config->flip_desk;
 }
 
@@ -146,12 +150,17 @@
    e_widget_frametable_object_append(of, ob, 1, 1, 1, 1, 1, 1, 1, 1);
    ob = e_widget_label_add(evas, _("Drag no place button"));
    e_widget_frametable_object_append(of, ob, 1, 2, 1, 1, 1, 1, 1, 1);
+   ob = e_widget_label_add(evas, _("Drag desktop button"));
+   e_widget_frametable_object_append(of, ob, 1, 3, 1, 1, 1, 1, 1, 1);
    ob = e_widget_button_add(evas, _("Click to set"), NULL, _grab_wnd_show, (void *)GRAB_BUTTON_DRAG, cfdata);
    e_widget_frametable_object_append(of, ob, 2, 1, 1, 1, 1, 1, 0, 0);
    cfdata->gui.o_btn1 = ob;
    ob = e_widget_button_add(evas, _("Click to set"), NULL, _grab_wnd_show, (void *)GRAB_BUTTON_NOPLACE, cfdata);
    e_widget_frametable_object_append(of, ob, 2, 2, 1, 1, 1, 1, 0, 0);
    cfdata->gui.o_btn2 = ob;
+   ob = e_widget_button_add(evas, _("Click to set"), NULL, _grab_wnd_show, (void *)GRAB_BUTTON_DESK, cfdata);
+   e_widget_frametable_object_append(of, ob, 2, 3, 1, 1, 1, 1, 0, 0);
+   cfdata->gui.o_btn3 = ob;
    _advanced_update_button_label(cfdata);
    e_widget_list_object_append(o, of, 1, 1, 0.5);   
    
@@ -171,6 +180,7 @@
    pager_config->drag_resist = cfdata->drag_resist;
    pager_config->btn_drag = cfdata->btn_drag;
    pager_config->btn_noplace = cfdata->btn_noplace;
+   pager_config->btn_desk = cfdata->btn_desk;
    pager_config->flip_desk = cfdata->flip_desk;
    _pager_cb_config_updated();
    e_config_save_queue();
@@ -193,6 +203,12 @@
    else
      snprintf(label, sizeof(label), _("Click to set"));
    e_widget_button_label_set(cfdata->gui.o_btn2, label);
+   
+   if (cfdata->btn_desk)
+     snprintf(label, sizeof(label), _("Button %i"), cfdata->btn_desk);
+   else
+     snprintf(label, sizeof(label), _("Click to set"));
+   e_widget_button_label_set(cfdata->gui.o_btn3, label);
 }
 
 static void
@@ -206,6 +222,8 @@
 
    if ((Pager_Grab_Button)data1 == GRAB_BUTTON_DRAG)
      cfdata->grab.btn = 1;
+   else if ((Pager_Grab_Button)data1 == GRAB_BUTTON_NOPLACE)
+     cfdata->grab.btn = 2;
    else
      cfdata->grab.btn = 0;
 
@@ -265,8 +283,10 @@
      {
 	if (cfdata->grab.btn == 1)
 	  cfdata->btn_drag = ev->button;
-	else
+	else if (cfdata->grab.btn == 2)
 	  cfdata->btn_noplace = ev->button;
+	else
+	  cfdata->btn_desk = ev->button;
      }
    else
      {
@@ -295,8 +315,10 @@
      {
 	if (cfdata->grab.btn == 1)
 	  cfdata->btn_drag = 0;
-	else
+	else if (cfdata->grab.btn == 2)
 	  cfdata->btn_noplace = 0;
+	else
+	  cfdata->btn_desk = 0;
 	_grab_wnd_hide(cfdata);
      }
    return 1;
Index: e_mod_main.c
===================================================================
RCS file: /cvs/e/e17/apps/e/src/modules/pager/e_mod_main.c,v
retrieving revision 1.207
diff -u -r1.207 e_mod_main.c
--- e_mod_main.c	3 Feb 2007 02:44:59 -0000	1.207
+++ e_mod_main.c	20 Feb 2007 22:50:31 -0000
@@ -60,13 +60,21 @@
 
 struct _Pager_Desk
 {
-   Pager       *pager;
-   E_Desk      *desk;
-   Evas_List   *wins;
-   Evas_Object *o_desk;
-   Evas_Object *o_layout;
-   int          xpos, ypos;
-   int          current : 1;
+   Pager           *pager;
+   E_Desk          *desk;
+   Evas_List       *wins;
+   Evas_Object     *o_desk;
+   Evas_Object     *o_layout;
+   int              xpos, ypos;
+   int              current : 1;
+   struct {
+      Pager         *from_pager;
+      unsigned char  in_pager : 1;
+      unsigned char  start : 1;
+      int            x, y;
+      int            dx, dy;
+      int            button;
+   } drag;
 };
 
 struct _Pager_Win
@@ -80,6 +88,7 @@
       unsigned char  start : 1;
       unsigned char  in_pager : 1;
       unsigned char  no_place : 1;
+      unsigned char  desktop  : 1;
       int            x, y;
       int            dx, dy;
       int            button;
@@ -132,6 +141,7 @@
 static void _pager_desk_cb_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
 static void _pager_desk_cb_mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
 static void _pager_desk_cb_mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
+static void _pager_desk_cb_drag_finished(E_Drag *drag, int dropped);
 static void _pager_desk_cb_mouse_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info);
 static int _pager_popup_cb_timeout(void *data);
 static Pager *_pager_new(Evas *evas, E_Zone *zone);
@@ -143,6 +153,7 @@
 static Pager_Desk *_pager_desk_at_coord(Pager *p, Evas_Coord x, Evas_Coord y);
 static void _pager_desk_select(Pager_Desk *pd);
 static Pager_Desk *_pager_desk_find(Pager *p, E_Desk *desk);
+static void _pager_desk_switch(Pager_Desk *pd1, Pager_Desk *pd2);
 static Pager_Win *_pager_window_new(Pager_Desk *pd, E_Border *border);
 static void _pager_window_free(Pager_Win *pw);
 static void _pager_window_move(Pager_Win *pw);
@@ -163,7 +174,7 @@
    E_Gadcon_Client *gcc;
    Instance *inst;
    Evas_Coord x, y, w, h;
-   const char *drop[] = { "enlightenment/pager_win", "enlightenment/border" };
+   const char *drop[] = { "enlightenment/pager_win", "enlightenment/border", "enlightenment/desktop"};
    
    inst = E_NEW(Instance, 1);
    
@@ -182,7 +193,7 @@
      e_drop_handler_add(E_OBJECT(inst->gcc), inst,
 			_pager_inst_cb_enter, _pager_inst_cb_move,
 			_pager_inst_cb_leave, _pager_inst_cb_drop,
-			drop, 2, x, y, w, h);
+			drop, 3, x, y, w, h);
    evas_object_event_callback_add(o, EVAS_CALLBACK_MOVE,
 				  _pager_cb_obj_moveresize, inst);
    evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE,
@@ -425,6 +436,110 @@
    return NULL;
 }
 
+static void
+_pager_desk_switch(Pager_Desk *pd1, Pager_Desk *pd2)
+{
+   int d1, d2;
+   int tmp_x, tmp_y;
+   int c;
+   E_Zone     *zone1, *zone2;
+   E_Desk     *desk1, *desk2;
+   Pager_Win  *pw;
+   Evas_List  *l;
+
+   if (!pd1 || !pd2 || !pd1->desk || !pd2->desk) return;
+   if (pd1 == pd2) return;
+
+   desk1 = pd1->desk;
+   desk2 = pd2->desk;
+   zone1 = pd1->desk->zone;
+   zone2 = pd2->desk->zone;
+
+   /* Move opened windows from on desk to the other */
+   for (l = pd1->wins; l; l = l->next)
+     {
+        pw = l->data;
+        if (!pw || !pw->border) continue;
+	e_border_desk_set(pw->border, desk2);
+     }
+   for (l = pd2->wins; l; l = l->next)
+     {
+        pw = l->data; 
+        if (!pw || !pw->border) continue;
+	e_border_desk_set(pw->border, desk1);
+     }
+
+   /* Modify desktop names in the config */
+   for (l = e_config->desktop_names, c = 0; l && c < 2; l = l->next)
+     {
+	E_Config_Desktop_Name *tmp_dn;
+
+        tmp_dn = l->data;
+        if (!tmp_dn) continue;
+        if (tmp_dn->desk_x == desk1->x && 
+	    tmp_dn->desk_y == desk1->y && 
+	    tmp_dn->zone   == desk1->zone->num)
+          {
+             tmp_dn->desk_x = desk2->x;
+             tmp_dn->desk_y = desk2->y;
+	     tmp_dn->zone   = desk2->zone->num;
+             c++;
+          }
+        else if (tmp_dn->desk_x == desk2->x && 
+	         tmp_dn->desk_y == desk2->y && 
+		 tmp_dn->zone   == desk2->zone->num)
+          {
+             tmp_dn->desk_x = desk1->x;
+             tmp_dn->desk_y = desk1->y;
+	     tmp_dn->zone   = desk1->zone->num;
+             c++;
+          }
+     }
+   if (c > 0) e_config_save();
+   e_desk_name_update();
+
+   /* Modify desktop backgrounds in the config */
+   for (l = e_config->desktop_backgrounds, c = 0; l && c < 2; l = l->next)
+     {
+	E_Config_Desktop_Background *tmp_db;
+
+        tmp_db = l->data;
+        if (!tmp_db) continue;
+        if (tmp_db->desk_x == desk1->x && 
+	    tmp_db->desk_y == desk1->y && 
+	    tmp_db->zone   == desk1->zone->num)
+          {
+             tmp_db->desk_x = desk2->x; 
+             tmp_db->desk_y = desk2->y; 
+             tmp_db->zone   = desk2->zone->num; 
+             c++;
+          }
+        else if (tmp_db->desk_x == desk2->x && 
+	         tmp_db->desk_y == desk2->y && 
+		 tmp_db->zone   == desk2->zone->num)
+          {
+             tmp_db->desk_x = desk1->x; 
+             tmp_db->desk_y = desk1->y; 
+             tmp_db->zone   = desk1->zone->num; 
+             c++;
+          }
+     }
+   if (c > 0) e_config_save();
+
+
+   /* If the current desktop has been switched, force to update of the screen */
+   if (desk2 == e_desk_current_get(zone2)) 
+     {
+	desk2->visible = 0;
+	e_desk_show(desk2);
+     }
+   if (desk1 == e_desk_current_get(zone1)) 
+     {
+	desk1->visible = 0;
+	e_desk_show(desk1);
+     }
+}
+
 static Pager_Win  *
 _pager_window_new(Pager_Desk *pd, E_Border *border)
 {
@@ -1317,8 +1432,8 @@
 
    ev = event_info;
    pw = data;
-   if (!pw) return;
-   if (pw->border->lock_user_location) return;
+   if (!pw || pw->border->lock_user_location) return;
+   if (ev->button == pager_config->btn_desk) return;
    if ((ev->button == pager_config->btn_drag) || 
        (ev->button == pager_config->btn_noplace))
      {
@@ -1347,6 +1462,7 @@
    ev = event_info;
    pw = data;
    if (!pw) return;
+   if (ev->button == pager_config->btn_desk) return;
    if ((ev->button == pager_config->btn_drag) ||
        (ev->button == pager_config->btn_noplace))
      {  
@@ -1443,8 +1559,8 @@
 	     pw->drag.from_pager = pw->desk->pager;
 	     pw->drag.from_pager->dragging = 1;
 	     pw->drag.in_pager = 0;
-	     e_util_evas_fake_mouse_up_later(evas_object_evas_get(pw->desk->pager->o_table),
-					     pw->drag.button);
+//	     e_util_evas_fake_mouse_up_later(evas_object_evas_get(pw->desk->pager->o_table),
+//					     pw->drag.button);
 //	     evas_event_feed_mouse_up(evas_object_evas_get(pw->desk->pager->o_table),
 //				      pw->drag.button, EVAS_BUTTON_NONE, 
 //				      ecore_x_current_time_get(), NULL);
@@ -1604,6 +1720,7 @@
    E_Event_Dnd_Drop *ev;
    Instance *inst;
    Pager_Desk *pd;
+   Pager_Desk *pd2 = NULL;
    E_Border *bd = NULL;
    Evas_List *l;
    int dx = 0, dy = 0;
@@ -1639,6 +1756,12 @@
 	     dx = (wx - wx2) / 2;
 	     dy = (wy - wy2) / 2;
 	  }
+	else if (!strcmp(type, "enlightenment/desktop"))
+	  {
+	     pd2 = ev->data;
+             if (!pd2) return;
+	     _pager_desk_switch(pd, pd2);
+	  }
 	else
 	  return;
 
@@ -1680,6 +1803,20 @@
 
    ev = event_info;
    pd = data;
+   if (!pd) return;
+   if (ev->button == pager_config->btn_desk)
+     {
+	Evas_Coord ox, oy;
+
+	evas_object_geometry_get(pd->o_desk, &ox, &oy, NULL, NULL);
+	pd->drag.start = 1;
+	pd->drag.in_pager = 1;
+	pd->drag.dx = ox - ev->canvas.x;
+	pd->drag.dy = oy - ev->canvas.y;
+	pd->drag.x = ev->canvas.x;
+	pd->drag.y = ev->canvas.y;
+	pd->drag.button = ev->button;
+     }
 }
 
 static void
@@ -1690,7 +1827,14 @@
 
    ev = event_info;
    pd = data;
+   if (!pd) return;
    /* FIXME: pd->pager->dragging is 0 when finishing a drag from desk to desk */
+   if (!pd->drag.from_pager)
+     {
+        pd->drag.in_pager = 0;
+        pd->drag.start = 0;
+        pd->pager->dragging = 0;
+     }
    if ((ev->button == 1) && (!pd->pager->dragging) &&
        (!pd->pager->just_dragged))
      {
@@ -1707,6 +1851,128 @@
 
    ev = event_info;
    pd = data;
+
+   if (!pd) return;
+   /* prevent drag for a few pixels */
+   if (pd->drag.start)
+     {
+	Evas_Coord dx, dy;
+	unsigned int resist = 0;
+
+	dx = pd->drag.x - ev->cur.output.x;
+	dy = pd->drag.y - ev->cur.output.y;
+	if (pd->pager && pd->pager->inst)
+	  resist = pager_config->drag_resist;
+
+	if (((dx * dx) + (dy * dy)) <= (resist * resist)) return;
+
+	pd->pager->dragging = 1;
+	pd->drag.start = 0;
+     }
+
+   if (pd->drag.in_pager)
+     {
+	E_Drag *drag;
+	Evas_Object *o, *oo, *o_icon;
+	Evas_Coord x, y, w, h;
+	const char *file = NULL, *part = NULL;
+	const char *drag_types[] = { "enlightenment/desktop" };
+	Pager_Win *pw;
+	Evas_List *l;
+	
+	evas_object_geometry_get(pd->o_desk, &x, &y, &w, &h);
+	drag = e_drag_new(pd->pager->inst->gcc->gadcon->zone->container,
+			  x, y, drag_types, 1, pd, -1,
+			  NULL, _pager_desk_cb_drag_finished);
+
+	/* set a background to the drag icon */
+	o = evas_object_rectangle_add(drag->evas);
+	evas_object_color_set(o, 255, 255, 255, 255);
+	evas_object_resize(o, w, h);
+	evas_object_show(o);
+
+	/* redraw the desktop theme above */
+        o = edje_object_add(drag->evas);
+	e_theme_edje_object_set(o, "base/theme/modules/pager", 
+				"e/modules/pager/desk");
+	evas_object_show(o);
+	e_drag_object_set(drag, o);
+
+	/* and redraw is content */
+	oo = e_layout_add(drag->evas);
+	e_layout_virtual_size_set(oo, pd->pager->zone->w, pd->pager->zone->h);
+	edje_object_part_swallow(o, "items", oo);
+	evas_object_show(oo);
+
+	for (l = pd->wins; l; l = l->next)
+	  {
+	     pw = l->data;
+	     if (!pw || pw->border->iconic) continue;
+
+	     o = edje_object_add(drag->evas);
+	     e_theme_edje_object_set(o, "base/theme/modules/pager", 
+				     "e/modules/pager/window");
+	     e_layout_pack(oo, o);
+	     e_layout_child_raise(o);
+	     e_layout_child_move(o, 
+				 pw->border->x - pw->desk->desk->zone->x, 
+				 pw->border->y - pw->desk->desk->zone->y);
+	     e_layout_child_resize(o, pw->border->w, pw->border->h);
+	     evas_object_show(o);
+
+	     if ((o_icon = e_border_icon_add(pw->border, drag->evas)))
+	       {
+		  evas_object_show(o_icon);
+		  edje_object_part_swallow(o, "icon", o_icon);
+	       }
+	  }
+	e_drag_resize(drag, w, h);
+	e_drag_start(drag, x - pd->drag.dx, y - pd->drag.dy);
+
+	pd->drag.from_pager = pd->pager;
+	pd->drag.from_pager->dragging = 1;
+	pd->drag.in_pager = 0;
+	e_util_evas_fake_mouse_up_later(evas_object_evas_get(pd->pager->o_table),
+					pd->drag.button);
+     }
+}
+
+static void
+_pager_desk_cb_drag_finished(E_Drag *drag, int dropped)
+{
+   Pager_Desk *pd;
+
+   pd = drag->data;
+   if (!pd) return;
+   if (!dropped)
+     {
+	/* wasn't dropped on pager, switch with current desktop */
+	Pager_Desk *pd2 = NULL;
+	Evas_List *l;
+	E_Desk *desk;
+
+	if (!pd->desk) return;
+	desk = e_desk_current_get(
+	         e_zone_current_get(
+		   e_container_current_get(
+		     e_manager_current_get())));
+	for (l = pager_config->instances; l && !pd2; l = l->next)
+	  {
+	     Instance *inst;
+	     Pager *pager = NULL;
+
+	     inst = l->data;
+	     if (!(pager = inst->pager)) continue;
+	     pd2 = _pager_desk_find(pager, desk);
+	  }
+	_pager_desk_switch(pd, pd2);
+     }
+   if (pd->drag.from_pager)
+     {
+	pd->drag.from_pager->dragging = 0;
+	pd->drag.from_pager->just_dragged = 0;
+     }
+   pd->drag.from_pager = NULL;
 }
 
 static void
@@ -1756,6 +2022,7 @@
    E_CONFIG_VAL(D, T, resize, UCHAR);
    E_CONFIG_VAL(D, T, btn_drag, UCHAR);
    E_CONFIG_VAL(D, T, btn_noplace, UCHAR);
+   E_CONFIG_VAL(D, T, btn_desk, UCHAR);
    E_CONFIG_VAL(D, T, flip_desk, UINT);
 
    pager_config = e_config_domain_load("module.pager", conf_edd);
@@ -1770,6 +2037,7 @@
 	pager_config->resize = PAGER_RESIZE_BOTH;
 	pager_config->btn_drag = 1;
 	pager_config->btn_noplace = 2;
+	pager_config->btn_desk = 0;
 	pager_config->flip_desk = 0;
      }
    E_CONFIG_LIMIT(pager_config->popup_speed, 0.1, 10.0);
@@ -1777,9 +2045,10 @@
    E_CONFIG_LIMIT(pager_config->drag_resist, 0, 50);
    E_CONFIG_LIMIT(pager_config->resize, PAGER_RESIZE_HORZ, PAGER_RESIZE_BOTH);
    E_CONFIG_LIMIT(pager_config->flip_desk, 0, 1);
-   E_CONFIG_LIMIT(pager_config->scale, 0, 1);
-   E_CONFIG_LIMIT(pager_config->btn_drag, 1, 32);
-   E_CONFIG_LIMIT(pager_config->btn_noplace, 1, 32);
+   if (pager_config->scale > 1) pager_config->scale = 1;
+   if (pager_config->btn_drag > 32) pager_config->btn_drag = 32;
+   if (pager_config->btn_noplace > 32) pager_config->btn_noplace = 32;
+   if (pager_config->btn_desk > 32) pager_config->btn_desk = 32;
 
    pager_config->handlers = evas_list_append
      (pager_config->handlers, ecore_event_handler_add
Index: e_mod_main.h
===================================================================
RCS file: /cvs/e/e17/apps/e/src/modules/pager/e_mod_main.h,v
retrieving revision 1.49
diff -u -r1.49 e_mod_main.h
--- e_mod_main.h	19 Nov 2006 08:58:05 -0000	1.49
+++ e_mod_main.h	20 Feb 2007 22:50:31 -0000
@@ -36,6 +36,7 @@
 
    unsigned char    btn_drag;
    unsigned char    btn_noplace;
+   unsigned char    btn_desk;
    unsigned int     flip_desk;
 };
 
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to