summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhinav <abhinav.prsai@gmail.com>2025-05-31 13:12:32 +0100
committerAbhinav <abhinav.prsai@gmail.com>2025-05-31 13:12:32 +0100
commit3a1674608199a450f8dca541a80cce12334923e3 (patch)
treefc4fbd26de2430e2fe1b8afa9f0ba4a3dc01f19f
parent17d90488c53326f2e52706d5dc2761799775b5e7 (diff)
added option for new windows to take focus
-rw-r--r--src/defs.h1
-rw-r--r--src/parser.c10
-rw-r--r--src/sxwm.c13
3 files changed, 22 insertions, 2 deletions
diff --git a/src/defs.h b/src/defs.h
index 0a71029..db71409 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -89,6 +89,7 @@ typedef struct {
int resize_master_amt;
int snap_distance;
int bindsn;
+ Bool new_win_focus;
Binding binds[256];
char **should_float[256];
} Config;
diff --git a/src/parser.c b/src/parser.c
index 6bf1294..5dfb0f7 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1,11 +1,11 @@
#define _POSIX_C_SOURCE 200809L
+#include <X11/Xlib.h>
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-#include <errno.h>
#include <X11/keysym.h>
#include "parser.h"
@@ -212,6 +212,14 @@ found:; // label followed by declaration is a C23 extension
else if (!strcmp(key, "swap_border_colour")) {
cfg->border_swap_col = parse_col(rest);
}
+ else if (!strcmp(key, "new_win_focus")) {
+ if (!strcmp(rest, "true")) {
+ cfg->new_win_focus = True;
+ }
+ else {
+ cfg->new_win_focus = False;
+ }
+ }
else if (!strcmp(key, "master_width")) {
float mf = atoi(rest) / 100.0f;
for (int i = 0; i < MAX_MONITORS; i++) {
diff --git a/src/sxwm.c b/src/sxwm.c
index 689fc59..b748445 100644
--- a/src/sxwm.c
+++ b/src/sxwm.c
@@ -14,6 +14,7 @@
* (C) Abhinav Prasai 2025
*/
+#include <X11/X.h>
#include <err.h>
#include <stdio.h>
#include <limits.h>
@@ -828,10 +829,19 @@ void hdl_map_req(XEvent *xev)
tile();
else if (c->floating)
XRaiseWindow(dpy, w);
+
+ if (user_config.new_win_focus) {
+ focused = c;
+ XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
+ send_wm_take_focus(c->win);
+ }
+
XMapWindow(dpy, w);
for (Client *c = workspaces[current_ws]; c; c = c->next)
if (c->win == w)
c->mapped = True;
+
+
update_borders();
}
@@ -1044,6 +1054,7 @@ void init_defaults(void)
default_config.resize_master_amt = 5;
default_config.snap_distance = 5;
default_config.bindsn = 0;
+ default_config.new_win_focus = True;
for (unsigned long i = 0; i < LENGTH(binds); i++) {
default_config.binds[i].mods = binds[i].mods;
@@ -1778,4 +1789,4 @@ int main(int ac, char **av)
printf("sxwm: starting...\n");
run();
return 0;
-} \ No newline at end of file
+}