diff --git a/src/desktops.c b/src/desktops.c index 64c33f4e..06e957cd 100644 --- a/src/desktops.c +++ b/src/desktops.c @@ -717,6 +717,15 @@ DeskGet(unsigned int desk) return _DeskGet(desk); } +Desk * +DeskGetValid(unsigned int desk) +{ + if (desk >= Conf.desks.num) + desk = 0; + + return _DeskGet(desk); +} + Desk * DeskGetRelative(Desk * dsk, int inc) { @@ -846,7 +855,7 @@ ChangeNumberOfDesktops(unsigned int quantity) for (j = 0; j < num; j++) { if (EoGetDeskNum(lst[j]) >= quantity) - EwinMoveToDesktop(lst[j], _DeskGet(quantity - 1)); + EwinMoveToDesktop(lst[j], _DeskGet(0)); } while (Conf.desks.num > quantity) diff --git a/src/desktops.h b/src/desktops.h index 017d8241..5a493006 100644 --- a/src/desktops.h +++ b/src/desktops.h @@ -62,6 +62,7 @@ struct _desk { /* desktops.c */ Desk *DeskGet(unsigned int desk); +Desk *DeskGetValid(unsigned int desk); Desk *DeskGetRelative(Desk * dsk, int inc); void DeskGetArea(const Desk * dsk, int *ax, int *ay); void DeskSetArea(Desk * dsk, int ax, int ay); diff --git a/src/snaps.c b/src/snaps.c index 720319db..d9637971 100644 --- a/src/snaps.c +++ b/src/snaps.c @@ -1429,7 +1429,7 @@ SnapshotEwinApply(EWin * ewin) EoSetSticky(ewin, sn->sticky); if (use_flags & SNAP_USE_DESK) - EoSetDesk(ewin, DeskGet(sn->desktop)); + EoSetDesk(ewin, DeskGetValid(sn->desktop)); if (use_flags & SNAP_USE_SIZE) { diff --git a/src/windowmatch.c b/src/windowmatch.c index d490b1bc..60b3f20e 100644 --- a/src/windowmatch.c +++ b/src/windowmatch.c @@ -671,7 +671,7 @@ WindowMatchEwinOpsAction(EWin * ewin, int op, const char *args) break; case EWIN_OP_DESK: - EoSetDesk(ewin, DeskGet(atoi(args))); + EoSetDesk(ewin, DeskGetValid(atoi(args))); break; #if 0 /* Causes crash */