magnet patch

This commit is contained in:
yosh 2023-01-15 23:35:39 -05:00
parent 5b5babb21b
commit ddc8ef736d
6 changed files with 265 additions and 18 deletions

2
README
View File

@ -11,6 +11,8 @@ The patches applied in the patched branch include:
* warp-on-movetogroup.diff - when moving a window to another group with
window-movetogroup-n, the pointer automatically focuses the next available
window in the group
* magnet-tiles.diff - taken from https://github.com/mlukow/OpenBSD-patches,
refer to that repository to see what it adds
you can clone the linux branch of this repository and apply patches individually
if you don't want all the patches the patched branch offers

View File

@ -518,6 +518,7 @@ void kbfunc_ptrmove(void *, struct cargs *);
void kbfunc_client_snap(void *, struct cargs *);
void kbfunc_client_move(void *, struct cargs *);
void kbfunc_client_resize(void *, struct cargs *);
void kbfunc_client_tile(void *, struct cargs *);
void kbfunc_client_close(void *, struct cargs *);
void kbfunc_client_lower(void *, struct cargs *);
void kbfunc_client_raise(void *, struct cargs *);

9
conf.c
View File

@ -104,6 +104,7 @@ static const struct {
{ FUNC_CC(window-movetogroup-7, client_movetogroup, 7) },
{ FUNC_CC(window-movetogroup-8, client_movetogroup, 8) },
{ FUNC_CC(window-movetogroup-9, client_movetogroup, 9) },
{ FUNC_CC(window-center, client_snap, 0) },
{ FUNC_CC(window-snap-up, client_snap, (CWM_UP)) },
{ FUNC_CC(window-snap-down, client_snap, (CWM_DOWN)) },
{ FUNC_CC(window-snap-right, client_snap, (CWM_RIGHT)) },
@ -130,6 +131,14 @@ static const struct {
{ FUNC_CC(window-resize-down-big, client_resize, (CWM_DOWN_BIG)) },
{ FUNC_CC(window-resize-right-big, client_resize, (CWM_RIGHT_BIG)) },
{ FUNC_CC(window-resize-left-big, client_resize, (CWM_LEFT_BIG)) },
{ FUNC_CC(window-tile-up, client_tile, (CWM_UP)) },
{ FUNC_CC(window-tile-down, client_tile, (CWM_DOWN)) },
{ FUNC_CC(window-tile-left, client_tile, (CWM_LEFT)) },
{ FUNC_CC(window-tile-right, client_tile, (CWM_RIGHT)) },
{ FUNC_CC(window-tile-up-left, client_tile, (CWM_UP_LEFT)) },
{ FUNC_CC(window-tile-up-right, client_tile, (CWM_UP_RIGHT)) },
{ FUNC_CC(window-tile-down-left, client_tile, (CWM_DOWN_LEFT)) },
{ FUNC_CC(window-tile-down-right, client_tile, (CWM_DOWN_RIGHT)) },
{ FUNC_CC(window-menu-label, client_menu_label, 0) },
{ FUNC_SC(window-cycle, client_cycle, (CWM_CYCLE_FORWARD)) },

18
cwmrc.5
View File

@ -421,6 +421,24 @@ Snap window to top-left corner.
Snap window to bottom-right corner.
.It window-snap-down-left
Snap window to bottom-left corner.
.It window-tile-up
Fill the top half of the screen with the window.
.It window-tile-down
Fill the bottom half of the screen with the window.
.It window-tile-left
Fill the left half of the screen with the window.
.It window-tile-right
Fill the right half of the screen with the window.
.It window-tile-up-left
Fill the top left quarter of the screen with the window.
.It window-tile-up-right
Fill the top right quarter of the screen with the window.
.It window-tile-down-left
Fill the down left quarter of the screen with the window.
.It window-tile-down-right
Fill the down right quarter of the screen with the window.
.It window-center
Centers the window on the screen.
.It pointer-move-up
Move pointer
.Ar moveamount

View File

@ -304,30 +304,79 @@ kbfunc_client_snap(void *ctx, struct cargs *cargs)
cc->geom.y + cc->geom.h / 2, 1);
flags = cargs->flag;
while (flags) {
if (flags & CWM_UP) {
cc->geom.y = area.y;
flags &= ~CWM_UP;
}
if (flags & CWM_LEFT) {
cc->geom.x = area.x;
flags &= ~CWM_LEFT;
}
if (flags & CWM_RIGHT) {
cc->geom.x = area.x + area.w - cc->geom.w -
(cc->bwidth * 2);
flags &= ~CWM_RIGHT;
}
if (flags & CWM_DOWN) {
cc->geom.y = area.y + area.h - cc->geom.h -
(cc->bwidth * 2);
flags &= ~CWM_DOWN;
if (flags) {
while (flags) {
if (flags & CWM_UP) {
cc->geom.y = area.y;
flags &= ~CWM_UP;
}
if (flags & CWM_LEFT) {
cc->geom.x = area.x;
flags &= ~CWM_LEFT;
}
if (flags & CWM_RIGHT) {
cc->geom.x = area.x + area.w - cc->geom.w -
(cc->bwidth * 2);
flags &= ~CWM_RIGHT;
}
if (flags & CWM_DOWN) {
cc->geom.y = area.y + area.h - cc->geom.h -
(cc->bwidth * 2);
flags &= ~CWM_DOWN;
}
}
} else {
cc->geom.x = area.x + (area.w - cc->geom.w) / 2 - cc->bwidth;
cc->geom.y = area.y + (area.h - cc->geom.h) / 2 - cc->bwidth;
}
client_move(cc);
client_ptr_inbound(cc, 1);
}
void
kbfunc_client_tile(void *ctx, struct cargs *cargs)
{
struct client_ctx *cc = ctx;
struct screen_ctx *sc = cc->sc;
struct geom area;
int flags;
area = screen_area(sc,
cc->geom.x + cc->geom.w / 2,
cc->geom.y + cc->geom.h / 2, 1);
flags = cargs->flag;
if (flags & CWM_UP) {
cc->geom.y = area.y;
cc->geom.h = area.h / 2 - (cc->bwidth * 2);
} else if (flags & CWM_DOWN) {
cc->geom.y = area.y + area.h / 2;
cc->geom.h = area.h / 2 - (cc->bwidth * 2);
} else {
cc->geom.y = area.y;
cc->geom.h = area.h - (cc->bwidth * 2);
}
if (flags & CWM_LEFT) {
cc->geom.x = area.x;
cc->geom.w = area.w / 2 - (cc->bwidth * 2);
} else if (flags & CWM_RIGHT) {
cc->geom.x = area.x + area.w / 2;
cc->geom.w = area.w / 2 - (cc->bwidth * 2);
} else {
cc->geom.x = area.x;
cc->geom.w = area.w - (cc->bwidth * 2);
}
client_resize(cc, 1);
client_move(cc);
client_ptr_inbound(cc, 1);
XSync(X_Dpy, True);
}
void
kbfunc_client_close(void *ctx, struct cargs *cargs)
{

168
patches/magnet-tiles.diff Normal file
View File

@ -0,0 +1,168 @@
diff --git a/calmwm.h b/calmwm.h
index 95e3c8d..4026764 100644
--- a/calmwm.h
+++ b/calmwm.h
@@ -506,6 +506,7 @@ void kbfunc_ptrmove(void *, struct cargs *);
void kbfunc_client_snap(void *, struct cargs *);
void kbfunc_client_move(void *, struct cargs *);
void kbfunc_client_resize(void *, struct cargs *);
+void kbfunc_client_tile(void *, struct cargs *);
void kbfunc_client_close(void *, struct cargs *);
void kbfunc_client_lower(void *, struct cargs *);
void kbfunc_client_raise(void *, struct cargs *);
diff --git a/conf.c b/conf.c
index 53ca295..19d0e95 100644
--- a/conf.c
+++ b/conf.c
@@ -102,6 +102,7 @@ static const struct {
{ FUNC_CC(window-movetogroup-7, client_movetogroup, 7) },
{ FUNC_CC(window-movetogroup-8, client_movetogroup, 8) },
{ FUNC_CC(window-movetogroup-9, client_movetogroup, 9) },
+ { FUNC_CC(window-center, client_snap, 0) },
{ FUNC_CC(window-snap-up, client_snap, (CWM_UP)) },
{ FUNC_CC(window-snap-down, client_snap, (CWM_DOWN)) },
{ FUNC_CC(window-snap-right, client_snap, (CWM_RIGHT)) },
@@ -128,6 +129,14 @@ static const struct {
{ FUNC_CC(window-resize-down-big, client_resize, (CWM_DOWN_BIG)) },
{ FUNC_CC(window-resize-right-big, client_resize, (CWM_RIGHT_BIG)) },
{ FUNC_CC(window-resize-left-big, client_resize, (CWM_LEFT_BIG)) },
+ { FUNC_CC(window-tile-up, client_tile, (CWM_UP)) },
+ { FUNC_CC(window-tile-down, client_tile, (CWM_DOWN)) },
+ { FUNC_CC(window-tile-left, client_tile, (CWM_LEFT)) },
+ { FUNC_CC(window-tile-right, client_tile, (CWM_RIGHT)) },
+ { FUNC_CC(window-tile-up-left, client_tile, (CWM_UP_LEFT)) },
+ { FUNC_CC(window-tile-up-right, client_tile, (CWM_UP_RIGHT)) },
+ { FUNC_CC(window-tile-down-left, client_tile, (CWM_DOWN_LEFT)) },
+ { FUNC_CC(window-tile-down-right, client_tile, (CWM_DOWN_RIGHT)) },
{ FUNC_CC(window-menu-label, client_menu_label, 0) },
{ FUNC_SC(window-cycle, client_cycle, (CWM_CYCLE_FORWARD)) },
diff --git a/cwmrc.5 b/cwmrc.5
index ab70d25..80d6f03 100644
--- a/cwmrc.5
+++ b/cwmrc.5
@@ -411,6 +411,24 @@ Snap window to top-left corner.
Snap window to bottom-right corner.
.It window-snap-down-left
Snap window to bottom-left corner.
+.It window-tile-up
+Fill the top half of the screen with the window.
+.It window-tile-down
+Fill the bottom half of the screen with the window.
+.It window-tile-left
+Fill the left half of the screen with the window.
+.It window-tile-right
+Fill the right half of the screen with the window.
+.It window-tile-up-left
+Fill the top left quarter of the screen with the window.
+.It window-tile-up-right
+Fill the top right quarter of the screen with the window.
+.It window-tile-down-left
+Fill the down left quarter of the screen with the window.
+.It window-tile-down-right
+Fill the down right quarter of the screen with the window.
+.It window-center
+Centers the window on the screen.
.It pointer-move-up
Move pointer
.Ar moveamount
diff --git a/kbfunc.c b/kbfunc.c
index 2d5d1ce..24f27ad 100644
--- a/kbfunc.c
+++ b/kbfunc.c
@@ -304,28 +304,77 @@ kbfunc_client_snap(void *ctx, struct cargs *cargs)
cc->geom.y + cc->geom.h / 2, 1);
flags = cargs->flag;
- while (flags) {
- if (flags & CWM_UP) {
- cc->geom.y = area.y;
- flags &= ~CWM_UP;
- }
- if (flags & CWM_LEFT) {
- cc->geom.x = area.x;
- flags &= ~CWM_LEFT;
- }
- if (flags & CWM_RIGHT) {
- cc->geom.x = area.x + area.w - cc->geom.w -
- (cc->bwidth * 2);
- flags &= ~CWM_RIGHT;
- }
- if (flags & CWM_DOWN) {
- cc->geom.y = area.y + area.h - cc->geom.h -
- (cc->bwidth * 2);
- flags &= ~CWM_DOWN;
+
+ if (flags) {
+ while (flags) {
+ if (flags & CWM_UP) {
+ cc->geom.y = area.y;
+ flags &= ~CWM_UP;
+ }
+ if (flags & CWM_LEFT) {
+ cc->geom.x = area.x;
+ flags &= ~CWM_LEFT;
+ }
+ if (flags & CWM_RIGHT) {
+ cc->geom.x = area.x + area.w - cc->geom.w -
+ (cc->bwidth * 2);
+ flags &= ~CWM_RIGHT;
+ }
+ if (flags & CWM_DOWN) {
+ cc->geom.y = area.y + area.h - cc->geom.h -
+ (cc->bwidth * 2);
+ flags &= ~CWM_DOWN;
+ }
}
+ } else {
+ cc->geom.x = area.x + (area.w - cc->geom.w) / 2 - cc->bwidth;
+ cc->geom.y = area.y + (area.h - cc->geom.h) / 2 - cc->bwidth;
+ }
+
+ client_move(cc);
+ client_ptr_inbound(cc, 1);
+}
+
+void
+kbfunc_client_tile(void *ctx, struct cargs *cargs)
+{
+ struct client_ctx *cc = ctx;
+ struct screen_ctx *sc = cc->sc;
+ struct geom area;
+ int flags;
+
+ area = screen_area(sc,
+ cc->geom.x + cc->geom.w / 2,
+ cc->geom.y + cc->geom.h / 2, 1);
+
+ flags = cargs->flag;
+
+ if (flags & CWM_UP) {
+ cc->geom.y = area.y;
+ cc->geom.h = area.h / 2 - (cc->bwidth * 2);
+ } else if (flags & CWM_DOWN) {
+ cc->geom.y = area.y + area.h / 2;
+ cc->geom.h = area.h / 2 - (cc->bwidth * 2);
+ } else {
+ cc->geom.y = area.y;
+ cc->geom.h = area.h - (cc->bwidth * 2);
+ }
+
+ if (flags & CWM_LEFT) {
+ cc->geom.x = area.x;
+ cc->geom.w = area.w / 2 - (cc->bwidth * 2);
+ } else if (flags & CWM_RIGHT) {
+ cc->geom.x = area.x + area.w / 2;
+ cc->geom.w = area.w / 2 - (cc->bwidth * 2);
+ } else {
+ cc->geom.x = area.x;
+ cc->geom.w = area.w - (cc->bwidth * 2);
}
+
+ client_resize(cc, 1);
client_move(cc);
client_ptr_inbound(cc, 1);
+ XSync(X_Dpy, True);
}
void