From: Daniel Déchelotte <[email protected]>
No more ghost dock when switching sides: the real swap happens immediately, you
can still adjust vertically afterwards
Removed two functions in superfluous that are no longer used
Consolidated all code testing whether an appicon is entirely on the screen into
the static function onScreen() (dock.c)
---
src/dock.c | 196 +++++++++++++++--------------------------------------
src/superfluous.c | 103 ----------------------------
src/superfluous.h | 1 -
3 files changed, 53 insertions(+), 247 deletions(-)
diff --git a/src/dock.c b/src/dock.c
index bc13c2b..ef382e2 100644
--- a/src/dock.c
+++ b/src/dock.c
@@ -127,6 +127,8 @@ static WDock* getDrawer(WScreen *scr, int y_index);
static int indexOfHole(WDock *drawer, WAppIcon *moving_aicon, int redocking);
static void drawerConsolidateIcons(WDock *drawer);
+static int onScreen(WScreen *scr, int x, int y);
+
static void make_keys(void)
{
if (dCommand != NULL)
@@ -1690,12 +1692,9 @@ static WAppIcon *restore_icon_state(WScreen *scr,
WMPropList *info, int type, in
wwarning(_("bad value in docked icon state info %s"),
WMGetFromPLString(dPosition));
/* check position sanity */
- /* incomplete section! */
+ /* *Very* incomplete section! */
if (type == WM_DOCK) {
aicon->xindex = 0;
- if (aicon->yindex < 0)
- wwarning(_("bad value in docked icon position
%i,%i"),
- aicon->xindex, aicon->yindex);
}
} else {
aicon->yindex = index;
@@ -1735,19 +1734,11 @@ WAppIcon *wClipRestoreState(WScreen *scr, WMPropList
*clip_state)
if (!WMIsPLString(value)) {
COMPLAIN("Position");
} else {
- WMRect rect;
- int flags;
-
if (sscanf(WMGetFromPLString(value), "%i,%i",
&icon->x_pos, &icon->y_pos) != 2)
COMPLAIN("Position");
/* check position sanity */
- rect.pos.x = icon->x_pos;
- rect.pos.y = icon->y_pos;
- rect.size.width = rect.size.height = ICON_SIZE;
-
- wGetRectPlacementInfo(scr, rect, &flags);
- if (flags & (XFLAG_DEAD | XFLAG_PARTIAL))
+ if (!onScreen(scr, icon->x_pos, icon->y_pos))
wScreenKeepInside(scr, &icon->x_pos,
&icon->y_pos, ICON_SIZE, ICON_SIZE);
}
}
@@ -1787,19 +1778,11 @@ WDock *wDockRestoreState(WScreen *scr, WMPropList
*dock_state, int type)
if (!WMIsPLString(value)) {
COMPLAIN("Position");
} else {
- WMRect rect;
- int flags;
-
if (sscanf(WMGetFromPLString(value), "%i,%i",
&dock->x_pos, &dock->y_pos) != 2)
COMPLAIN("Position");
/* check position sanity */
- rect.pos.x = dock->x_pos;
- rect.pos.y = dock->y_pos;
- rect.size.width = rect.size.height = ICON_SIZE;
-
- wGetRectPlacementInfo(scr, rect, &flags);
- if (flags & (XFLAG_DEAD | XFLAG_PARTIAL)) {
+ if (!onScreen(scr, dock->x_pos, dock->y_pos)) {
int x = dock->x_pos;
wScreenKeepInside(scr, &x, &dock->y_pos,
ICON_SIZE, ICON_SIZE);
}
@@ -2454,10 +2437,6 @@ Bool wDockSnapIcon(WDock *dock, WAppIcon *icon, int
req_x, int req_y, int *ret_x
int i, offset = ICON_SIZE / 2;
WAppIcon *aicon = NULL;
WAppIcon *nicon = NULL;
- int max_y_icons;
-
- /* TODO: XINERAMA, for these */
- max_y_icons = scr->scr_height / ICON_SIZE - 1;
if (wPreferences.flags.noupdates)
return False;
@@ -2481,18 +2460,8 @@ Bool wDockSnapIcon(WDock *dock, WAppIcon *icon, int
req_x, int req_y, int *ret_x
ex_x = (req_x + offset - dx) / ICON_SIZE;
/* check if the icon is outside the screen boundaries */
- {
- WMRect rect;
- int flags;
-
- rect.pos.x = dx + ex_x * ICON_SIZE;
- rect.pos.y = dy + ex_y * ICON_SIZE;
- rect.size.width = rect.size.height = ICON_SIZE;
-
- wGetRectPlacementInfo(scr, rect, &flags);
- if (flags & (XFLAG_DEAD | XFLAG_PARTIAL))
- return False;
- }
+ if (!onScreen(scr, dx + ex_x * ICON_SIZE, dy + ex_y * ICON_SIZE))
+ return False;
switch (dock->type) {
case WM_DOCK:
@@ -2534,7 +2503,7 @@ Bool wDockSnapIcon(WDock *dock, WAppIcon *icon, int
req_x, int req_y, int *ret_x
if (abs(ex_x) > DOCK_DETTACH_THRESHOLD)
return False;
- if (ex_y >= 0 && ex_y <= max_y_icons && (aicon == icon
|| !aicon)) {
+ if (aicon == icon || !aicon) {
*ret_x = 0;
*ret_y = ex_y;
return True;
@@ -2546,7 +2515,6 @@ Bool wDockSnapIcon(WDock *dock, WAppIcon *icon, int
req_x, int req_y, int *ret_x
else
sig = -1;
- closest = -1;
done = 0;
/* look for closest free slot */
for (i = 0; i < (DOCK_DETTACH_THRESHOLD + 1) * 2 &&
!done; i++) {
@@ -2554,8 +2522,8 @@ Bool wDockSnapIcon(WDock *dock, WAppIcon *icon, int
req_x, int req_y, int *ret_x
done = 1;
closest = sig * (i / 2) + ex_y;
- /* check if this slot is used */
- if (closest >= 0) {
+ /* check if this slot is fully on the screen
and not used */
+ if (onScreen(scr, dx, dy + closest *
ICON_SIZE)) {
for (j = 0; j < dock->max_icons; j++) {
if (dock->icon_array[j]
&&
dock->icon_array[j]->yindex == closest) {
@@ -2568,9 +2536,11 @@ Bool wDockSnapIcon(WDock *dock, WAppIcon *icon, int
req_x, int req_y, int *ret_x
/* slot is used by a drawer */
done = done && !getDrawer(scr, closest);
}
+ else // !onScreen
+ done = 0;
sig = -sig;
}
- if (done && closest >= 0 && closest <= max_y_icons &&
+ if (done &&
((ex_y >= closest && ex_y - closest <
DOCK_DETTACH_THRESHOLD + 1)
|| (ex_y < closest && closest - ex_y <=
DOCK_DETTACH_THRESHOLD + 1))) {
*ret_x = 0;
@@ -2580,7 +2550,7 @@ Bool wDockSnapIcon(WDock *dock, WAppIcon *icon, int
req_x, int req_y, int *ret_x
} else { /* !redocking */
/* if slot is free and the icon is close enough, return
it */
- if (!aicon && ex_x == 0 && ex_y >= 0 && ex_y <=
max_y_icons) {
+ if (!aicon && ex_x == 0) {
*ret_x = 0;
*ret_y = ex_y;
return True;
@@ -2680,11 +2650,15 @@ Bool wDockSnapIcon(WDock *dock, WAppIcon *icon, int
req_x, int req_y, int *ret_x
return False;
}
-static int onScreen(WScreen *scr, int x, int y, int sx, int ex, int sy, int ey)
+static int onScreen(WScreen *scr, int x, int y)
{
- WMRect rect = wmkrect(x, y, ICON_SIZE, ICON_SIZE);
+ WMRect rect;
int flags;
+ rect.pos.x = x;
+ rect.pos.y = y;
+ rect.size.width = rect.size.height = ICON_SIZE;
+
wGetRectPlacementInfo(scr, rect, &flags);
return !(flags & (XFLAG_DEAD | XFLAG_PARTIAL));
@@ -2706,7 +2680,7 @@ Bool wDockFindFreeSlot(WDock *dock, int *x_pos, int
*y_pos)
int x, y;
int i, done = False;
int corner;
- int sx = 0, sy = 0, ex = scr->scr_width, ey = scr->scr_height;
+ int sx = 0, ex = scr->scr_width, ey = scr->scr_height;
int extra_count = 0;
if (dock->type == WM_DRAWER) {
@@ -2927,7 +2901,7 @@ Bool wDockFindFreeSlot(WDock *dock, int *x_pos, int
*y_pos)
tx = dock->x_pos + x * ICON_SIZE;
y = -i;
ty = dock->y_pos + y * ICON_SIZE;
- if (slot_map[XY2OFS(x, y)] == 0 && onScreen(scr, tx,
ty, sx, ex, sy, ey)) {
+ if (slot_map[XY2OFS(x, y)] == 0 && onScreen(scr, tx,
ty)) {
*x_pos = x;
*y_pos = y;
done = 1;
@@ -2935,7 +2909,7 @@ Bool wDockFindFreeSlot(WDock *dock, int *x_pos, int
*y_pos)
}
y = i;
ty = dock->y_pos + y * ICON_SIZE;
- if (slot_map[XY2OFS(x, y)] == 0 && onScreen(scr, tx,
ty, sx, ex, sy, ey)) {
+ if (slot_map[XY2OFS(x, y)] == 0 && onScreen(scr, tx,
ty)) {
*x_pos = x;
*y_pos = y;
done = 1;
@@ -2947,7 +2921,7 @@ Bool wDockFindFreeSlot(WDock *dock, int *x_pos, int
*y_pos)
ty = dock->y_pos + y * ICON_SIZE;
x = -i;
tx = dock->x_pos + x * ICON_SIZE;
- if (slot_map[XY2OFS(x, y)] == 0 && onScreen(scr, tx,
ty, sx, ex, sy, ey)) {
+ if (slot_map[XY2OFS(x, y)] == 0 && onScreen(scr, tx,
ty)) {
*x_pos = x;
*y_pos = y;
done = 1;
@@ -2955,7 +2929,7 @@ Bool wDockFindFreeSlot(WDock *dock, int *x_pos, int
*y_pos)
}
x = i;
tx = dock->x_pos + x * ICON_SIZE;
- if (slot_map[XY2OFS(x, y)] == 0 && onScreen(scr, tx,
ty, sx, ex, sy, ey)) {
+ if (slot_map[XY2OFS(x, y)] == 0 && onScreen(scr, tx,
ty)) {
*x_pos = x;
*y_pos = y;
done = 1;
@@ -3640,7 +3614,7 @@ static void handleDockMove(WDock *dock, WAppIcon *aicon,
XEvent *event)
int x = aicon->x_pos, y = aicon->y_pos;;
int shad_x = x, shad_y = y;
XEvent ev;
- int grabbed = 0, swapped = 0, done;
+ int grabbed = 0, done, previously_on_right, now_on_right,
previous_x_pos;
Pixmap ghost = None;
int superfluous = wPreferences.superfluous; /* we catch it to avoid
problems */
@@ -3666,23 +3640,10 @@ static void handleDockMove(WDock *dock, WAppIcon
*aicon, XEvent *event)
XClearWindow(dpy, scr->dock_shadow);
}
XMapWindow(dpy, scr->dock_shadow);
- } else {
- int i;
- WDrawerChain *dc;
- /* Find out the actual height of the dock, to create its shadow
*/
- y = 0;
- for (i = 0; i < dock->max_icons; i++) {
- if (dock->icon_array[i] != NULL &&
dock->icon_array[i]->yindex > y)
- y = dock->icon_array[i]->yindex;
- }
- for (dc = scr->drawers; dc; dc = dc->next) {
- if ((dc->adrawer->y_pos - dock->y_pos) / ICON_SIZE > y)
- y = (dc->adrawer->y_pos - dock->y_pos) /
ICON_SIZE;
- }
- y++;
- XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE, ICON_SIZE * y);
}
+ previously_on_right = now_on_right = dock->on_right_side;
+ previous_x_pos = dock->x_pos;
done = 0;
while (!done) {
WMMaskEvent(dpy, PointerMotionMask | ButtonReleaseMask |
ButtonPressMask
@@ -3718,61 +3679,25 @@ static void handleDockMove(WDock *dock, WAppIcon
*aicon, XEvent *event)
moveDock(dock, x, y);
break;
case WM_DOCK:
- /* move vertically if pointer is inside the
dock */
- if ((dock->on_right_side && ev.xmotion.x_root
>= dock->x_pos - ICON_SIZE)
- || (!dock->on_right_side &&
ev.xmotion.x_root <= dock->x_pos + ICON_SIZE * 2)) {
-
- x = ev.xmotion.x_root - ofs_x;
- y = ev.xmotion.y_root - ofs_y;
- wScreenKeepInside(scr, &x, &y,
ICON_SIZE, ICON_SIZE);
- moveDock(dock, dock->x_pos, y);
- }
- /* move horizontally to change sides */
x = ev.xmotion.x_root - ofs_x;
- if (!dock->on_right_side) {
-
- /* is on left */
- if (ev.xmotion.x_root > dock->x_pos +
ICON_SIZE * 2) {
- XMoveWindow(dpy,
scr->dock_shadow, scr->scr_width - ICON_SIZE
- - DOCK_EXTRA_SPACE
- 1, dock->y_pos);
- if (superfluous && ghost ==
None) {
- ghost =
MakeGhostDock(dock, dock->x_pos,
-
scr->scr_width - ICON_SIZE
- -
DOCK_EXTRA_SPACE - 1, dock->y_pos);
-
XSetWindowBackgroundPixmap(dpy, scr->dock_shadow, ghost);
- XClearWindow(dpy,
scr->dock_shadow);
- }
- XMapRaised(dpy,
scr->dock_shadow);
- swapped = 1;
- } else {
- if (superfluous && ghost !=
None) {
- XFreePixmap(dpy, ghost);
- ghost = None;
- }
- XUnmapWindow(dpy,
scr->dock_shadow);
- swapped = 0;
- }
- } else {
- /* is on right */
- if (ev.xmotion.x_root < dock->x_pos -
ICON_SIZE) {
- XMoveWindow(dpy,
scr->dock_shadow, DOCK_EXTRA_SPACE, dock->y_pos);
- if (superfluous && ghost ==
None) {
- ghost =
MakeGhostDock(dock, dock->x_pos,
-
DOCK_EXTRA_SPACE, dock->y_pos);
-
XSetWindowBackgroundPixmap(dpy, scr->dock_shadow, ghost);
- XClearWindow(dpy,
scr->dock_shadow);
- }
- XMapRaised(dpy,
scr->dock_shadow);
- swapped = -1;
- } else {
- XUnmapWindow(dpy,
scr->dock_shadow);
- swapped = 0;
- if (superfluous && ghost !=
None) {
- XFreePixmap(dpy, ghost);
- ghost = None;
- }
- }
+ y = ev.xmotion.y_root - ofs_y;
+ if (previously_on_right)
+ {
+ now_on_right = (ev.xmotion.x_root >=
previous_x_pos - ICON_SIZE);
+ }
+ else
+ {
+ now_on_right = (ev.xmotion.x_root >
previous_x_pos + ICON_SIZE * 2);
+ }
+ if (now_on_right != dock->on_right_side)
+ {
+ dock->on_right_side = now_on_right;
+ swapDock(dock);
+ wArrangeIcons(scr, False);
}
+ // Also perform the vertical move
+ wScreenKeepInside(scr, &x, &y, ICON_SIZE,
ICON_SIZE);
+ moveDock(dock, dock->x_pos, y);
break;
case WM_DRAWER:
{
@@ -3782,13 +3707,13 @@ static void handleDockMove(WDock *dock, WAppIcon
*aicon, XEvent *event)
x = ev.xmotion.x_root - ofs_x;
y = ev.xmotion.y_root - ofs_y;
snapped = wDockSnapIcon(real_dock, aicon, x, y,
&ix, &iy, True);
- if (snapped) {
- shad_x = real_dock->x_pos + ix * wPreferences.icon_size;
- shad_y = real_dock->y_pos + iy * wPreferences.icon_size;
- XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
- }
- moveDock(dock, x, y);
- break;
+ if (snapped) {
+ shad_x = real_dock->x_pos + ix *
wPreferences.icon_size;
+ shad_y = real_dock->y_pos + iy *
wPreferences.icon_size;
+ XMoveWindow(dpy, scr->dock_shadow,
shad_x, shad_y);
+ }
+ moveDock(dock, x, y);
+ break;
}
}
break;
@@ -3817,19 +3742,7 @@ static void handleDockMove(WDock *dock, WAppIcon *aicon,
XEvent *event)
shad_y);
XUnmapWindow(dpy, scr->dock_shadow);
moveDock(dock, shad_x, shad_y);
- } else {
- XUnmapWindow(dpy, scr->dock_shadow);
- }
- XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE,
ICON_SIZE);
- if (dock->type == WM_DOCK) {
- if (swapped != 0) {
- if (swapped > 0)
- dock->on_right_side = 1;
- else
- dock->on_right_side = 0;
- swapDock(dock);
- wArrangeIcons(scr, False);
- }
+ XResizeWindow(dpy, scr->dock_shadow, ICON_SIZE,
ICON_SIZE);
}
done = 1;
break;
@@ -4739,9 +4652,6 @@ static WDock * drawerRestoreState(WScreen *scr,
WMPropList *drawer_state)
x = scr->dock->x_pos;
}
y_index = (y - scr->dock->y_pos) / ICON_SIZE;
- if (y_index <= 0) {
- y_index = 1;
- }
if (y_index >= scr->dock->max_icons) {
/* Here we should do something more intelligent, since
it
* can happen even if the user hasn't hand-edited his
diff --git a/src/superfluous.c b/src/superfluous.c
index a2e58c9..0c95ed4 100644
--- a/src/superfluous.c
+++ b/src/superfluous.c
@@ -137,109 +137,6 @@ void DoKaboom(WScreen * scr, Window win, int x, int y)
#endif /* NORMAL_ICON_KABOOM */
}
-static int addGhostTile(WScreen *scr, RImage *back, Pixmap which, int dy, int
height,
- unsigned long red_mask,
unsigned long green_mask, unsigned long blue_mask)
-{
- XImage *img;
- RImage *dock_image;
-
- img = XGetImage(dpy, which, 0, 0, wPreferences.icon_size, height,
AllPlanes, ZPixmap);
- if (!img) {
- RReleaseImage(back);
- return -1;
- }
- img->red_mask = red_mask;
- img->green_mask = green_mask;
- img->blue_mask = blue_mask;
-
- dock_image = RCreateImageFromXImage(scr->rcontext, img, NULL);
- XDestroyImage(img);
- if (!dock_image) {
- RReleaseImage(back);
- return -1;
- }
- RCombineAreaWithOpaqueness(back, dock_image, 0, 0, wPreferences.icon_size,
- height, 0, dy, 30 *
256 / 100);
- RReleaseImage(dock_image);
- return 0;
-}
-
-Pixmap MakeGhostDock(WDock * dock, int sx, int dx, int y)
-{
- WScreen *scr = dock->screen_ptr;
- WDrawerChain *dc;
- WDock *drawer;
- XImage *img;
- RImage *back;
- Pixmap pixmap;
- int i, virtual_tiles, h, j, n;
- unsigned long red_mask, green_mask, blue_mask;
-
- virtual_tiles = 0;
- for (i = 0; i < dock->max_icons; i++) {
- if (dock->icon_array[i] != NULL && dock->icon_array[i]->yindex
> virtual_tiles)
- virtual_tiles = dock->icon_array[i]->yindex;
- }
- for (dc = scr->drawers; dc != NULL; dc = dc->next) {
- if (dc->adrawer->y_pos - dock->y_pos > virtual_tiles *
wPreferences.icon_size)
- virtual_tiles = (dc->adrawer->y_pos - dock->y_pos) /
wPreferences.icon_size;
- }
- virtual_tiles++;
- h = virtual_tiles * wPreferences.icon_size;
- h = (y + h > scr->scr_height) ? scr->scr_height - y : h;
- virtual_tiles = h / wPreferences.icon_size; /* The visible ones */
- if (h % wPreferences.icon_size)
- virtual_tiles++; /* There is one partially visible tile
at end */
-
- img = XGetImage(dpy, scr->root_win, dx, y, wPreferences.icon_size, h,
AllPlanes, ZPixmap);
- if (!img)
- return None;
-
- red_mask = img->red_mask;
- green_mask = img->green_mask;
- blue_mask = img->blue_mask;
-
- back = RCreateImageFromXImage(scr->rcontext, img, NULL);
- XDestroyImage(img);
- if (!back) {
- return None;
- }
-
- for (i = 0; i < dock->max_icons; i++) {
- if (dock->icon_array[i] != NULL && dock->icon_array[i]->yindex
< virtual_tiles) {
- Pixmap which;
- j = dock->icon_array[i]->yindex *
wPreferences.icon_size;
- n = (h - j < wPreferences.icon_size) ? h - j :
wPreferences.icon_size;
- if (dock->icon_array[i]->icon->pixmap)
- which = dock->icon_array[i]->icon->pixmap;
- else
- which = dock->icon_array[i]->icon->core->window;
- if (addGhostTile(scr, back, which, j, n, red_mask, green_mask,
blue_mask))
- return None; /* back is released by addGhostTile */
- }
- }
- for (dc = scr->drawers; dc != NULL; dc = dc->next) {
- Pixmap which;
- drawer = dc->adrawer;
- if (drawer->y_pos >= scr->scr_height)
- continue;
- j = drawer->y_pos - dock->y_pos;
- n = (h - j < wPreferences.icon_size) ? h - j : wPreferences.icon_size;
- if (drawer->icon_array[0]->icon->pixmap)
- which = drawer->icon_array[0]->icon->pixmap;
- else
- which = drawer->icon_array[0]->icon->core->window;
- if (addGhostTile(scr, back, which, j, n, red_mask, green_mask,
blue_mask))
- return None; /* back is released by addGhostTile */
- }
-
- RConvertImage(scr->rcontext, back, &pixmap);
-
- RReleaseImage(back);
-
- return pixmap;
-}
-
Pixmap MakeGhostIcon(WScreen * scr, Drawable drawable)
{
RImage *back;
diff --git a/src/superfluous.h b/src/superfluous.h
index b7b70b1..b3424cd 100644
--- a/src/superfluous.h
+++ b/src/superfluous.h
@@ -24,7 +24,6 @@
#include "dock.h"
void DoKaboom(WScreen *scr, Window win, int x, int y);
-Pixmap MakeGhostDock(WDock *dock, int sx, int dx, int y);
Pixmap MakeGhostIcon(WScreen *scr, Drawable drawable);
void DoWindowBirth(WWindow *wwin);
#endif
--
1.7.10.4
--
To unsubscribe, send mail to [email protected].