move config-related variables and functions to config.c
This commit is contained in:
parent
12351bdf99
commit
f98f9e6826
@ -397,8 +397,8 @@ void wm_client_border(Wm *wm, Client *c)
|
||||
TrueColor, &vinfo);
|
||||
|
||||
cmap = XCreateColormap(wm->display, c->window, vinfo.visual, AllocNone);
|
||||
XParseColor(wm->display, cmap, wm->cfg_focused_border_col, &fcolor);
|
||||
XParseColor(wm->display, cmap, wm->cfg_border_col, &color);
|
||||
XParseColor(wm->display, cmap, wm->config.focused_border_col, &fcolor);
|
||||
XParseColor(wm->display, cmap, wm->config.border_col, &color);
|
||||
XAllocColor(wm->display, cmap, &fcolor);
|
||||
XAllocColor(wm->display, cmap, &color);
|
||||
|
||||
@ -408,7 +408,7 @@ void wm_client_border(Wm *wm, Client *c)
|
||||
// DEBUG_PRINT("wm_client_border window: %d\n", c->window)
|
||||
}
|
||||
|
||||
XSetWindowBorderWidth(wm->display, c->window, wm->cfg_border_width);
|
||||
XSetWindowBorderWidth(wm->display, c->window, wm->config.border_width);
|
||||
|
||||
// DEBUG_PRINT("drawing border for: %d\n", c->window);
|
||||
if (wm_client_is_focused(wm, c)) {
|
||||
|
@ -136,10 +136,10 @@ void wm_keypress_handler(Wm *wm, XKeyPressedEvent e)
|
||||
Client *c;
|
||||
Keybind k;
|
||||
|
||||
DEBUG_PRINT("wm->cfg_kb_count: %d\n", wm->cfg_kb_count);
|
||||
DEBUG_PRINT("wm->config.kb_count: %d\n", wm->config.kb_count);
|
||||
|
||||
for (int i = 0; i < wm->cfg_kb_count; i++) {
|
||||
k = wm->cfg_keybinds[i];
|
||||
for (int i = 0; i < wm->config.kb_count; i++) {
|
||||
k = wm->config.keybinds[i];
|
||||
if (k.mask == e.state && k.keysym == XLookupKeysym(&e, 0))
|
||||
{
|
||||
(*k.func)(wm, &k.args);
|
||||
@ -195,7 +195,7 @@ void wm_motion_handler(Wm *wm, XMotionEvent e)
|
||||
c = wm_client_find(wm, e.window);
|
||||
RETURN_IF_NULL(c)
|
||||
|
||||
if(!wm_client_is_focused(wm, c) && wm->cfg_focus_on_motion)
|
||||
if(!wm_client_is_focused(wm, c) && wm->config.focus_on_motion)
|
||||
wm_client_focus(wm, c);
|
||||
}
|
||||
|
||||
|
@ -219,9 +219,9 @@ TreeNode* wm_treenode_remove_client(Wm *wm, TreeNode *root, Client *client)
|
||||
client->ws->tree = *sibling_node;
|
||||
|
||||
client->ws->tree.pos = (Rect) {
|
||||
.x = wm->cfg_border_width, .y = wm->cfg_border_width + dock_y ,
|
||||
.w = client->ws->monitor->info.width - wm->cfg_border_width*2,
|
||||
.h = client->ws->monitor->info.height - wm->cfg_border_width*2 - dock_y,
|
||||
.x = wm->config.border_width, .y = wm->config.border_width + dock_y ,
|
||||
.w = client->ws->monitor->info.width - wm->config.border_width*2,
|
||||
.h = client->ws->monitor->info.height - wm->config.border_width*2 - dock_y,
|
||||
};
|
||||
|
||||
assert(client->ws->tree.children.size == 2);
|
||||
|
132
src/wm.c
132
src/wm.c
@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include "config.h"
|
||||
#include "handler.h"
|
||||
#include "client.h"
|
||||
#include "util.h"
|
||||
@ -193,9 +194,9 @@ void wm_ws_tree_insert_client(Wm *wm, Workspace *ws, Client *client)
|
||||
ws->tree.type = NODE_CLIENT;
|
||||
ws->tree.client = client;
|
||||
ws->tree.pos = (Rect) {
|
||||
.x = wm->cfg_border_width, .y = wm->cfg_border_width + dock_y ,
|
||||
.w = ws->monitor->info.width - wm->cfg_border_width*2,
|
||||
.h = ws->monitor->info.height - wm->cfg_border_width*2 - dock_y,
|
||||
.x = wm->config.border_width, .y = wm->config.border_width + dock_y ,
|
||||
.w = ws->monitor->info.width - wm->config.border_width*2,
|
||||
.h = ws->monitor->info.height - wm->config.border_width*2 - dock_y,
|
||||
};
|
||||
return;
|
||||
}
|
||||
@ -310,8 +311,8 @@ void wm_mstack(Wm *wm, Monitor *m)
|
||||
}
|
||||
c->x = 0;
|
||||
c->y = sy;
|
||||
c->w = wm->smon->info.width-wm->cfg_border_width*2;
|
||||
c->h = (wm->smon->info.height-wm->cfg_border_width*2)-sy;
|
||||
c->w = wm->smon->info.width-wm->config.border_width*2;
|
||||
c->h = (wm->smon->info.height-wm->config.border_width*2)-sy;
|
||||
ch = wm_client_to_xwchanges(c);
|
||||
DEBUG_PRINT("mstack client: %p\n", c);
|
||||
// XGetWMName(wm->display, c->window, &xt);
|
||||
@ -331,14 +332,14 @@ void wm_mstack(Wm *wm, Monitor *m)
|
||||
if (n == 0) {
|
||||
c->x = 0;
|
||||
c->y = sy;
|
||||
c->w = m->info.width*wm->cfg_ms_p-wm->cfg_border_width*2;
|
||||
c->h = (m->info.height-wm->cfg_border_width*2)-sy;
|
||||
c->w = m->info.width*wm->config.ms_p-wm->config.border_width*2;
|
||||
c->h = (m->info.height-wm->config.border_width*2)-sy;
|
||||
} else {
|
||||
c->x = (m->info.width*wm->cfg_ms_p);
|
||||
c->x = (m->info.width*wm->config.ms_p);
|
||||
c->y = ((n-1)*m->info.height/(cc_sws-1))+sy;
|
||||
c->w = (m->info.width - m->info.width*wm->cfg_ms_p) -
|
||||
wm->cfg_border_width*2;
|
||||
c->h = ((m->info.height)/(cc_sws-1)-wm->cfg_border_width*2);
|
||||
c->w = (m->info.width - m->info.width*wm->config.ms_p) -
|
||||
wm->config.border_width*2;
|
||||
c->h = ((m->info.height)/(cc_sws-1)-wm->config.border_width*2);
|
||||
}
|
||||
n++;
|
||||
ch = wm_client_to_xwchanges(c);
|
||||
@ -376,11 +377,6 @@ void wm_mstack(Wm *wm, Monitor *m)
|
||||
wm_monitor_clients_border(wm, m);
|
||||
}
|
||||
|
||||
void wm_set_layout(Wm *wm, void(*f)(Wm *wm, Monitor*))
|
||||
{
|
||||
wm->active_layout = f;
|
||||
}
|
||||
|
||||
void wm_layout(Wm *wm, Monitor *m)
|
||||
{
|
||||
RETURN_IF_NULL(m);
|
||||
@ -503,7 +499,7 @@ void wm_mainloop(Wm *wm)
|
||||
case EnterNotify:
|
||||
DEBUG_PRINT("pointer entered window: %d\n",
|
||||
(int)e.xcrossing.window);
|
||||
if (wm->cfg_focus_on_motion)
|
||||
if (wm->config.focus_on_motion)
|
||||
wm_client_focus(wm, wm_client_find(wm, e.xcrossing.window));
|
||||
break;
|
||||
case LeaveNotify:
|
||||
@ -559,8 +555,8 @@ void wm_init(Wm *wm)
|
||||
|
||||
// XUngrabKey(wm->display, AnyKey, AnyModifier, root.window);
|
||||
|
||||
// TODO: read config
|
||||
wm_init_cfg_def(wm);
|
||||
wm->config = (Config) {0};
|
||||
wm_cfg_init_def(&wm->config);
|
||||
wm_grab_keys(wm);
|
||||
|
||||
//XSetErrorHandler(&wm_other_wm_handler);
|
||||
@ -601,20 +597,9 @@ void wm_exit(Wm *wm)
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
void wm_init_cfg_def(Wm *wm)
|
||||
{
|
||||
wm->cfg_ms_p = 0.5;
|
||||
wm->cfg_border_col = "#222222";
|
||||
wm->cfg_focused_border_col = "#444444";
|
||||
wm->cfg_border_width = 2;
|
||||
wm->cfg_focus_on_motion = true;
|
||||
|
||||
wm_keybinds_init_def(wm);
|
||||
}
|
||||
|
||||
void wm_grab_keys(Wm *wm)
|
||||
{
|
||||
RETURN_IF_NULL(wm->cfg_keybinds)
|
||||
RETURN_IF_NULL(wm->config.keybinds)
|
||||
Keybind k;
|
||||
|
||||
// from dwm
|
||||
@ -637,8 +622,8 @@ void wm_grab_keys(Wm *wm)
|
||||
|
||||
XUngrabKey(wm->display, AnyKey, AnyModifier, wm->root.window);
|
||||
|
||||
for (int i = 0; i < wm->cfg_kb_count; i++) {
|
||||
k = wm->cfg_keybinds[i];
|
||||
for (int i = 0; i < wm->config.kb_count; i++) {
|
||||
k = wm->config.keybinds[i];
|
||||
for (int j = 0; j < 3; j++)
|
||||
XGrabKey(wm->display, XKeysymToKeycode(wm->display, k.keysym),
|
||||
k.mask | modifiers[j], wm->root.window, True, GrabModeAsync,
|
||||
@ -709,87 +694,6 @@ void wm_kb_switch_split_mode(Wm *wm, Arg *args)
|
||||
wm->smon->workspaces[wm->smon->selws].split = args->i;
|
||||
}
|
||||
|
||||
void wm_keybinds_init_def(Wm *wm)
|
||||
{
|
||||
char *st[] = {"alacritty", NULL};
|
||||
char **sth = malloc(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;
|
||||
|
||||
Keybind k[] = {
|
||||
(Keybind) {Mod4Mask, XK_Return, *wm_kb_spawn,
|
||||
(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,
|
||||
(Arg) {.c = NULL}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_1, *wm_kb_switch_ws,
|
||||
(Arg) {.i = 0}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_2, *wm_kb_switch_ws,
|
||||
(Arg) {.i = 1}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_3, *wm_kb_switch_ws,
|
||||
(Arg) {.i = 2}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_4, *wm_kb_switch_ws,
|
||||
(Arg) {.i = 3}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_5, *wm_kb_switch_ws,
|
||||
(Arg) {.i = 4}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_6, *wm_kb_switch_ws,
|
||||
(Arg) {.i = 5}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_7, *wm_kb_switch_ws,
|
||||
(Arg) {.i = 6}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_8, *wm_kb_switch_ws,
|
||||
(Arg) {.i = 7}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_9, *wm_kb_switch_ws,
|
||||
(Arg) {.i = 8}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_h, *wm_kb_focus_dir,
|
||||
(Arg) {.i = LEFT}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_j, *wm_kb_focus_dir,
|
||||
(Arg) {.i = DOWN}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_k, *wm_kb_focus_dir,
|
||||
(Arg) {.i = UP}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_l, *wm_kb_focus_dir,
|
||||
(Arg) {.i = RIGHT}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_b, *wm_kb_switch_split_mode,
|
||||
(Arg) {.i = SPLIT_VERTICAL}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_v, *wm_kb_switch_split_mode,
|
||||
(Arg) {.i = SPLIT_HORIZ}},
|
||||
|
||||
(Keybind) {Mod4Mask, XK_t, *wm_kb_switch_split_mode,
|
||||
(Arg) {.i = SPLIT_TAB}},
|
||||
};
|
||||
|
||||
|
||||
size = sizeof(k);
|
||||
wm->cfg_kb_count = size / sizeof(Keybind);
|
||||
DEBUG_PRINT("sizeof k: %d\n", size);
|
||||
wm->cfg_keybinds = malloc(size);
|
||||
memcpy(wm->cfg_keybinds, k, size);
|
||||
}
|
||||
|
||||
struct sockaddr wm_socket_init(Wm *wm)
|
||||
{
|
||||
struct sockaddr_un sock_addr;
|
||||
|
40
src/wm.h
40
src/wm.h
@ -36,6 +36,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
|
||||
// TODO: when only 1 window on ws it is not focused
|
||||
@ -63,7 +64,6 @@ if (c == NULL) \
|
||||
typedef struct Client Client;
|
||||
typedef struct Workspace Workspace;
|
||||
typedef struct Monitor Monitor;
|
||||
typedef struct Keybind Keybind;
|
||||
typedef struct Arg Arg;
|
||||
typedef struct Wm Wm;
|
||||
|
||||
@ -97,23 +97,6 @@ struct Workspace {
|
||||
SplitMode split;
|
||||
};
|
||||
|
||||
struct Arg {
|
||||
int i;
|
||||
unsigned int ui;
|
||||
Client *c;
|
||||
char* s;
|
||||
char **sl;
|
||||
|
||||
int count;
|
||||
};
|
||||
|
||||
struct Keybind {
|
||||
unsigned int mask;
|
||||
KeySym keysym;
|
||||
void (*func)(Wm*, Arg*);
|
||||
Arg args;
|
||||
};
|
||||
|
||||
struct Wm {
|
||||
// TODO INIT
|
||||
Display *display;
|
||||
@ -127,15 +110,14 @@ struct Wm {
|
||||
|
||||
Client *focused_client;
|
||||
|
||||
// TODO: active layout not working
|
||||
void (*active_layout)(Wm *wm, Monitor*);
|
||||
float cfg_ms_p;
|
||||
char *cfg_border_col;
|
||||
char *cfg_focused_border_col;
|
||||
unsigned char cfg_border_width;
|
||||
Keybind *cfg_keybinds;
|
||||
int cfg_kb_count;
|
||||
bool cfg_focus_on_motion;
|
||||
// float cfg_ms_p;
|
||||
// char *cfg_border_col;
|
||||
// char *cfg_focused_border_col;
|
||||
// unsigned char cfg_border_width;
|
||||
// Keybind *cfg_keybinds;
|
||||
// int cfg_kb_count;
|
||||
// bool cfg_focus_on_motion;
|
||||
Config config;
|
||||
|
||||
int socket_fd;
|
||||
};
|
||||
@ -160,8 +142,6 @@ void wm_mainloop(Wm* wm);
|
||||
void wm_init(Wm *wm);
|
||||
void wm_exit(Wm *wm);
|
||||
|
||||
void wm_init_cfg_def(Wm *wm);
|
||||
|
||||
void wm_grab_keys(Wm *wm);
|
||||
void wm_kb_spawn(Wm *wm, Arg *args);
|
||||
void wm_kb_kill(Wm *wm, Arg *args);
|
||||
@ -170,8 +150,6 @@ void wm_kb_focus_dir(Wm *wm, Arg *args);
|
||||
void wm_kb_exit(Wm* wm, Arg *args);
|
||||
void wm_kb_switch_split_mode(Wm *wm, Arg *args);
|
||||
|
||||
void wm_keybinds_init_def(Wm *wm);
|
||||
|
||||
struct sockaddr wm_socket_init(Wm *wm);
|
||||
void wm_socket_cleanup(Wm *wm);
|
||||
void wm_settings_message_parse(Wm *wm, char *c, int len);
|
||||
|
Loading…
x
Reference in New Issue
Block a user