add function and keybind to exit wm, improve main loop
This commit is contained in:
72
wm.c
72
wm.c
@ -323,7 +323,6 @@ void wm_mainloop(Wm *wm)
|
|||||||
char *buffer;
|
char *buffer;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
while (1) {
|
|
||||||
|
|
||||||
// accepted_socket = accept(wm->socket_fd, &s, &t);
|
// accepted_socket = accept(wm->socket_fd, &s, &t);
|
||||||
// if (accepted_socket == -1) {
|
// if (accepted_socket == -1) {
|
||||||
@ -347,7 +346,7 @@ void wm_mainloop(Wm *wm)
|
|||||||
// fprintf(stderr, "errno: %d\n", errno);
|
// fprintf(stderr, "errno: %d\n", errno);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
while (XPending(wm->display)) {
|
while (wm->running) {
|
||||||
XEvent e;
|
XEvent e;
|
||||||
XNextEvent(wm->display, &e);
|
XNextEvent(wm->display, &e);
|
||||||
|
|
||||||
@ -394,7 +393,8 @@ void wm_mainloop(Wm *wm)
|
|||||||
DEBUG_PRINT("MapRequest: %d\n", (int)e.xmaprequest.window)
|
DEBUG_PRINT("MapRequest: %d\n", (int)e.xmaprequest.window)
|
||||||
wm_maprequest_handler(wm, e.xmaprequest);
|
wm_maprequest_handler(wm, e.xmaprequest);
|
||||||
break;
|
break;
|
||||||
}
|
default:
|
||||||
|
DEBUG_PRINT("default: %d\n", e.type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -412,6 +412,9 @@ void wm_init(Wm *wm)
|
|||||||
wm->display = d;
|
wm->display = d;
|
||||||
wm_monitors_open_all(wm, d);
|
wm_monitors_open_all(wm, d);
|
||||||
|
|
||||||
|
char *display_string = DisplayString(wm->display);
|
||||||
|
setenv("DISPLAY", display_string, 1);
|
||||||
|
|
||||||
// TODO: only testing
|
// TODO: only testing
|
||||||
// wm_socket_init();
|
// wm_socket_init();
|
||||||
|
|
||||||
@ -471,7 +474,29 @@ void wm_init(Wm *wm)
|
|||||||
|
|
||||||
wm->dock = -1;
|
wm->dock = -1;
|
||||||
|
|
||||||
|
wm->running = true;
|
||||||
wm_mainloop(wm);
|
wm_mainloop(wm);
|
||||||
|
wm_exit(wm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wm_exit(Wm *wm)
|
||||||
|
{
|
||||||
|
DEBUG_PRINT("%s\n", __func__);
|
||||||
|
Client *c;
|
||||||
|
|
||||||
|
XUngrabKey(wm->display, AnyKey, AnyModifier, wm->root.window);
|
||||||
|
|
||||||
|
// todo add clients to root client linked list
|
||||||
|
for (c = wm->smon->clients; c; c = c->next) {
|
||||||
|
XKillClient(wm->display, c->window);
|
||||||
|
}
|
||||||
|
for (c = wm->smon->clients; c; c = c->next) {
|
||||||
|
wm_client_free(wm, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG_PRINT("%s1\n", __func__);
|
||||||
|
XCloseDisplay(wm->display);
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wm_init_cfg_def(Wm *wm)
|
void wm_init_cfg_def(Wm *wm)
|
||||||
@ -490,10 +515,32 @@ void wm_grab_keys(Wm *wm)
|
|||||||
RETURN_IF_NULL(wm->cfg_keybinds)
|
RETURN_IF_NULL(wm->cfg_keybinds)
|
||||||
Keybind k;
|
Keybind k;
|
||||||
|
|
||||||
|
// from dwm
|
||||||
|
{
|
||||||
|
unsigned int i, j;
|
||||||
|
XModifierKeymap *modmap;
|
||||||
|
|
||||||
|
unsigned int numlockmask = 0;
|
||||||
|
modmap = XGetModifierMapping(wm->display);
|
||||||
|
for (i = 0; i < 8; i++)
|
||||||
|
for (j = 0; j < modmap->max_keypermod; j++)
|
||||||
|
if (modmap->modifiermap[i * modmap->max_keypermod + j]
|
||||||
|
== XKeysymToKeycode(wm->display, XK_Num_Lock))
|
||||||
|
numlockmask = (1 << i);
|
||||||
|
XFreeModifiermap(modmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
// from dwm
|
||||||
|
unsigned int modifiers[] = { 0, LockMask, 0|LockMask };
|
||||||
|
|
||||||
|
XUngrabKey(wm->display, AnyKey, AnyModifier, wm->root.window);
|
||||||
|
|
||||||
for (int i = 0; i < wm->cfg_kb_count; i++) {
|
for (int i = 0; i < wm->cfg_kb_count; i++) {
|
||||||
k = wm->cfg_keybinds[i];
|
k = wm->cfg_keybinds[i];
|
||||||
XGrabKey(wm->display, XKeysymToKeycode(wm->display, k.keysym), k.mask,
|
for (int j = 0; j < 3; j++)
|
||||||
wm->root.window, True, GrabModeAsync, GrabModeAsync);
|
XGrabKey(wm->display, XKeysymToKeycode(wm->display, k.keysym),
|
||||||
|
k.mask | modifiers[j], wm->root.window, True, GrabModeAsync,
|
||||||
|
GrabModeAsync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,6 +568,11 @@ void wm_kb_spawn(Wm *wm, Arg *args)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wm_kb_exit(Wm* wm, Arg *args)
|
||||||
|
{
|
||||||
|
wm->running = false;
|
||||||
|
}
|
||||||
|
|
||||||
void wm_kb_kill(Wm *wm, Arg *args)
|
void wm_kb_kill(Wm *wm, Arg *args)
|
||||||
{
|
{
|
||||||
Client *c;
|
Client *c;
|
||||||
@ -553,12 +605,22 @@ void wm_keybinds_init_def(Wm *wm)
|
|||||||
char *st[] = {"st", NULL};
|
char *st[] = {"st", NULL};
|
||||||
char **sth = malloc(sizeof(st));
|
char **sth = malloc(sizeof(st));
|
||||||
memcpy(sth, st, sizeof(st));
|
memcpy(sth, st, sizeof(st));
|
||||||
|
|
||||||
|
char *dmenu[] = {"i3-dmenu-desktop", NULL};
|
||||||
|
char **dmenuh = malloc(sizeof(dmenu));
|
||||||
|
memcpy(dmenuh, dmenu, sizeof(dmenu));
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
Keybind k[] = {
|
Keybind k[] = {
|
||||||
(Keybind) {Mod4Mask, XK_Return, *wm_kb_spawn,
|
(Keybind) {Mod4Mask, XK_Return, *wm_kb_spawn,
|
||||||
(Arg) {.sl = sth, .count = 2}},
|
(Arg) {.sl = sth, .count = 2}},
|
||||||
|
|
||||||
|
(Keybind) {Mod4Mask | ShiftMask, XK_q, *wm_kb_exit,
|
||||||
|
(Arg) {0}},
|
||||||
|
|
||||||
|
(Keybind) {Mod4Mask, XK_d, *wm_kb_spawn,
|
||||||
|
(Arg) {.sl = dmenuh, .count = 2}},
|
||||||
|
|
||||||
(Keybind) {Mod4Mask, XK_c, *wm_kb_kill,
|
(Keybind) {Mod4Mask, XK_c, *wm_kb_kill,
|
||||||
(Arg) {.c = NULL}},
|
(Arg) {.c = NULL}},
|
||||||
|
|
||||||
|
4
wm.h
4
wm.h
@ -117,6 +117,7 @@ struct Wm {
|
|||||||
Display *display;
|
Display *display;
|
||||||
Monitor *monitors;
|
Monitor *monitors;
|
||||||
Monitor *smon;
|
Monitor *smon;
|
||||||
|
bool running;
|
||||||
int wm_mc;
|
int wm_mc;
|
||||||
bool other_wm;
|
bool other_wm;
|
||||||
Client root;
|
Client root;
|
||||||
@ -149,6 +150,8 @@ void wm_spawn(Wm* wm, char **str);
|
|||||||
void wm_switch_ws(Wm* wm, int ws);
|
void wm_switch_ws(Wm* wm, int ws);
|
||||||
void wm_mainloop(Wm* wm);
|
void wm_mainloop(Wm* wm);
|
||||||
void wm_init(Wm *wm);
|
void wm_init(Wm *wm);
|
||||||
|
void wm_exit(Wm *wm);
|
||||||
|
|
||||||
void wm_init_cfg_def(Wm *wm);
|
void wm_init_cfg_def(Wm *wm);
|
||||||
|
|
||||||
void wm_grab_keys(Wm *wm);
|
void wm_grab_keys(Wm *wm);
|
||||||
@ -156,6 +159,7 @@ void wm_kb_spawn(Wm *wm, Arg *args);
|
|||||||
void wm_kb_kill(Wm *wm, Arg *args);
|
void wm_kb_kill(Wm *wm, Arg *args);
|
||||||
void wm_kb_switch_ws(Wm *wm, Arg *args);
|
void wm_kb_switch_ws(Wm *wm, Arg *args);
|
||||||
void wm_kb_focus_dir(Wm *wm, Arg *args);
|
void wm_kb_focus_dir(Wm *wm, Arg *args);
|
||||||
|
void wm_kb_exit(Wm* wm, Arg *args);
|
||||||
|
|
||||||
void wm_keybinds_init_def(Wm *wm);
|
void wm_keybinds_init_def(Wm *wm);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user