summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--README.md10
-rw-r--r--default_sxwmrc1
-rw-r--r--src/defs.h3
-rw-r--r--src/parser.c3
-rw-r--r--src/sxwm.c17
-rw-r--r--sxwm.18
7 files changed, 36 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3ec0b4a..35d7461 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
- **NEW**: Window swallowing
- **NEW**: New windows can now open as master window
- **NEW**: Scratchpads
+- **NEW**: Window centering
- **CHANGE**: Renamed `focus_previous` to `focus_prev`
- **CHANGE**: Invalid sample config
- **CHANGE**: Parser `$HOME` searching order. XDG Compliance
diff --git a/README.md b/README.md
index 0d26eeb..befd0f3 100644
--- a/README.md
+++ b/README.md
@@ -140,7 +140,8 @@ workspace : modifier + modifier + ... + key : swap n
| `master_decrease` | Shrinks master width. |
| `toggle_floating` | Toggles floating state of current window. |
| `global_floating` | Toggles floating state for all windows. |
-| `fullscreen` | Fullscreen toggle. |
+| `fullscreen` | Fullscreen the focused window. |
+| `centre_window` | Centre the focused window. |
### Example Bindings
@@ -168,9 +169,9 @@ workspace : mod + shift + 5 : swap 5
### Window Management
| Combo | Action |
| --------------------------- | ---------------------------------- |
-| Mouse | Focus under cursor |
-| `MOD` + Left Mouse | Move window with mouse |
-| `MOD` + Right Mouse | Resize window with mouse |
+| `Mouse` | Focus on click under cursor |
+| `MOD` + `Left Mouse` | Move window with mouse |
+| `MOD` + `Right Mouse` | Resize window with mouse |
| `MOD` + `j` / `k` | Focus next / previous |
| `MOD` + `Shift` + `j` / `k` | Move window in master stack |
| `MOD` + `,` / `.` | Focus prev / next monitor |
@@ -184,6 +185,7 @@ workspace : mod + shift + 5 : swap 5
| `MOD` + `Shift` + `q` | Close focused window |
| `MOD` + `Shift` + `e` | Quit sxwm |
| `MOD` + `r` | Reload configuration |
+| `MOD` + `c` | Centre window |
### Scratchpads
diff --git a/default_sxwmrc b/default_sxwmrc
index 7128526..e3c29b8 100644
--- a/default_sxwmrc
+++ b/default_sxwmrc
@@ -31,6 +31,7 @@ bind : mod + p : "dmenu_run"
# Window Management:
call : mod + shift + q : close_window
+call : mod + c : centre_window
call : mod + shift + e : quit
# Focus Movement:
diff --git a/src/defs.h b/src/defs.h
index 5476434..5796214 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -119,6 +119,7 @@ typedef struct {
Bool enabled;
} Scratchpad;
+extern void centre_window();
extern void close_focused(void);
extern void dec_gaps(void);
extern void focus_next(void);
@@ -139,4 +140,4 @@ extern void resize_stack_add(void);
extern void resize_stack_sub(void);
extern void toggle_floating(void);
extern void toggle_floating_global(void);
-extern void toggle_fullscreen(void); \ No newline at end of file
+extern void toggle_fullscreen(void);
diff --git a/src/parser.c b/src/parser.c
index eb0b1a8..79cf29b 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -37,6 +37,7 @@ static const struct {
{"toggle_floating", toggle_floating},
{"global_floating", toggle_floating_global},
{"fullscreen", toggle_fullscreen},
+ {"centre_window", centre_window},
{NULL, NULL}};
static void remap_and_dedupe_binds(Config *cfg)
@@ -691,4 +692,4 @@ const char **build_argv(const char *cmd)
free(tmp);
return argv;
#endif
-} \ No newline at end of file
+}
diff --git a/src/sxwm.c b/src/sxwm.c
index 5e86c75..8aa7bd8 100644
--- a/src/sxwm.c
+++ b/src/sxwm.c
@@ -38,6 +38,7 @@
#include "parser.h"
Client *add_client(Window w, int ws);
+/* void centre_window(); */
void change_workspace(int ws);
int clean_mask(int mask);
/* void close_focused(void); */
@@ -253,6 +254,20 @@ Client *add_client(Window w, int ws)
return c;
}
+void centre_window()
+{
+ if (!focused || !focused->mapped || !focused->floating) {
+ return;
+ }
+
+ int x = mons[focused->mon].x + (mons[focused->mon].w - focused->w) / 2;
+ int y = mons[focused->mon].y + (mons[focused->mon].h - focused->h) / 2;
+
+ focused->x = x;
+ focused->y = y;
+ XMoveWindow(dpy, focused->win, x, y);
+}
+
void change_workspace(int ws)
{
if (ws >= NUM_WORKSPACES || ws == current_ws) {
@@ -2657,4 +2672,4 @@ int main(int ac, char **av)
printf("sxwm: starting...\n");
run();
return 0;
-} \ No newline at end of file
+}
diff --git a/sxwm.1 b/sxwm.1
index 889a6ae..5eddd6f 100644
--- a/sxwm.1
+++ b/sxwm.1
@@ -182,6 +182,10 @@ The following internal functions are available for keybindings:
Closes the currently focused window.
.TP
+.B centre_window
+Centers the focused window.
+
+.TP
.B decrease_gaps
Decreases the gap size between windows.
@@ -321,6 +325,10 @@ Quit sxwm.
Reload configuration.
.TP
+.B MOD + c
+Center focused window.
+
+.TP
.B MOD + 1 to 9
Switch to workspace 1 through 9.