mirror of
https://github.com/vale981/bspwm
synced 2025-03-05 09:51:38 -05:00
Rules, XDG config & autostart
This commit is contained in:
parent
622197558e
commit
fa73a124c9
10 changed files with 95 additions and 20 deletions
4
Makefile
4
Makefile
|
@ -5,10 +5,10 @@ LIBS = `pkg-config --libs xcb xcb-icccm xcb-ewmh lua cairo`
|
|||
CFLAGS = -g -std=c99 -pedantic -Wall -Wextra
|
||||
LDFLAGS = $(LIBS)
|
||||
|
||||
PREFIX = /usr/local
|
||||
PREFIX ?= /usr/local
|
||||
BINPREFIX = $(PREFIX)/bin
|
||||
|
||||
WM_SRC = bspwm.c events.c luautils.c messages.c ewmh.c settings.c utils.c tree.c types.c
|
||||
WM_SRC = bspwm.c events.c luautils.c messages.c ewmh.c settings.c utils.c tree.c types.c rules.c
|
||||
CL_SRC = bspc.c
|
||||
ST_SRC = bsps.c
|
||||
|
||||
|
|
18
bspwm.c
18
bspwm.c
|
@ -2,7 +2,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
/* #include <signal.h> */
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
@ -16,6 +16,7 @@
|
|||
#include "types.h"
|
||||
#include "settings.h"
|
||||
#include "messages.h"
|
||||
#include "rules.h"
|
||||
#include "events.h"
|
||||
#include "common.h"
|
||||
#include "utils.h"
|
||||
|
@ -47,16 +48,16 @@ xcb_screen_t *screen_of_display(xcb_connection_t *dpy, int default_screen)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* void handle_zombie(int sig) */
|
||||
/* { */
|
||||
/* while (waitpid(-1, NULL, WNOHANG) > 0) */
|
||||
/* ; */
|
||||
/* signal(sig, handle_zombie); */
|
||||
/* } */
|
||||
void handle_zombie(int sig)
|
||||
{
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0)
|
||||
;
|
||||
signal(sig, handle_zombie);
|
||||
}
|
||||
|
||||
void setup(int default_screen)
|
||||
{
|
||||
/* signal(SIGCHLD, handle_zombie); */
|
||||
signal(SIGCHLD, handle_zombie);
|
||||
ewmh_init();
|
||||
/* screen = ewmh.screens[default_screen]; */
|
||||
/* screen = xcb_setup_roots_iterator(xcb_get_setup(dpy)).data; */
|
||||
|
@ -80,6 +81,7 @@ void setup(int default_screen)
|
|||
last_desk = NULL;
|
||||
desk_head = desk;
|
||||
desk_tail = desk;
|
||||
rule_head = make_rule();
|
||||
|
||||
split_mode = MODE_AUTOMATIC;
|
||||
}
|
||||
|
|
1
bspwm.h
1
bspwm.h
|
@ -12,6 +12,7 @@ desktop_t *desk;
|
|||
desktop_t *last_desk;
|
||||
desktop_t *desk_head;
|
||||
desktop_t *desk_tail;
|
||||
rule_t *rule_head;
|
||||
bool running;
|
||||
|
||||
enum { WM_PROTOCOLS, WM_DELETE_WINDOW, WM_COUNT };
|
||||
|
|
29
rules.c
Normal file
29
rules.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include <string.h>
|
||||
#include <xcb/xcb_icccm.h>
|
||||
#include "types.h"
|
||||
#include "bspwm.h"
|
||||
#include "rules.h"
|
||||
|
||||
rule_t *next_match(rule_t *r, xcb_window_t w)
|
||||
{
|
||||
if (r == NULL)
|
||||
return NULL;
|
||||
rule_t *cur = (r == NULL ? rule_head : r->next);
|
||||
rule_t *found = NULL;
|
||||
while (cur != NULL && found == NULL) {
|
||||
if (is_match(cur, w))
|
||||
found = cur;
|
||||
cur = cur->next;
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
bool is_match(rule_t *r, xcb_window_t w)
|
||||
{
|
||||
xcb_icccm_get_wm_class_reply_t wc;
|
||||
if (xcb_icccm_get_wm_class_reply(dpy, xcb_icccm_get_wm_class(dpy, w), &wc, NULL) == 1) {
|
||||
if ((r->cause.class_name == NULL || strstr(wc.class_name, r->cause.class_name) != NULL) && (r->cause.instance_name == NULL || strstr(wc.instance_name, r->cause.instance_name) != NULL))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
9
rules.h
Normal file
9
rules.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef _RULES_H
|
||||
#define _RULES_H
|
||||
|
||||
#define MATCH_ANY "_"
|
||||
|
||||
rule_t *next_match(rule_t *, xcb_window_t);
|
||||
bool is_match(rule_t *, xcb_window_t);
|
||||
|
||||
#endif
|
30
settings.c
30
settings.c
|
@ -1,12 +1,15 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <lua.h>
|
||||
#include <lualib.h>
|
||||
#include <lauxlib.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_event.h>
|
||||
#include "helpers.h"
|
||||
#include "types.h"
|
||||
#include "bspwm.h"
|
||||
#include "utils.h"
|
||||
#include "luautils.h"
|
||||
#include "common.h"
|
||||
|
@ -14,21 +17,42 @@
|
|||
|
||||
void load_settings(void)
|
||||
{
|
||||
char path[MAXLEN];
|
||||
lua_State *L = lua_open();
|
||||
luaopen_base(L);
|
||||
/* luaL_openlibs(L); */
|
||||
|
||||
if (luaL_loadfile(L, CONFIG_FILE) == 0) {
|
||||
snprintf(path, sizeof(path), "%s/%s/%s", getenv("XDG_CONFIG_HOME"), WM_NAME, CONFIG_FILE);
|
||||
|
||||
if (luaL_loadfile(L, path) == 0) {
|
||||
if (lua_pcall(L, 0, 0, 0) == 0)
|
||||
apply_settings(L);
|
||||
else
|
||||
die("error: cannot interpret configuration file\n");
|
||||
PUTS("error: cannot interpret configuration file\n");
|
||||
} else {
|
||||
die("error: could not load configuration file\n");
|
||||
PUTS("error: could not load configuration file\n");
|
||||
}
|
||||
|
||||
lua_close(L);
|
||||
}
|
||||
|
||||
void run_autostart(void)
|
||||
{
|
||||
char path[MAXLEN];
|
||||
|
||||
snprintf(path, sizeof(path), "%s/%s/%s", getenv("XDG_CONFIG_HOME"), WM_NAME, AUTOSTART_FILE);
|
||||
|
||||
if (fork() != 0)
|
||||
return;
|
||||
|
||||
if (dpy != NULL)
|
||||
close(xcb_get_file_descriptor(dpy));
|
||||
|
||||
execl(path, path);
|
||||
|
||||
PUTS("error: could not load autostart file\n");
|
||||
}
|
||||
|
||||
void apply_settings(lua_State *L)
|
||||
{
|
||||
string_expr(L, normal_border_color, "normal_border_color", NORMAL_BORDER_COLOR);
|
||||
|
|
|
@ -9,7 +9,8 @@
|
|||
#include "helpers.h"
|
||||
|
||||
#define WM_NAME "bspwm"
|
||||
#define CONFIG_FILE ".bspwmrc"
|
||||
#define CONFIG_FILE "bspwmrc"
|
||||
#define AUTOSTART_FILE "autostart"
|
||||
|
||||
#define OUTER_BORDER_WIDTH 2
|
||||
#define MAIN_BORDER_WIDTH 1
|
||||
|
|
5
types.c
5
types.c
|
@ -29,13 +29,14 @@ client_t *make_client(xcb_window_t win)
|
|||
{
|
||||
client_t *c = malloc(sizeof(client_t));
|
||||
c->window = win;
|
||||
c->floating = c->fullscreen = c->locked = false;
|
||||
c->floating = c->transient = c->fullscreen = c->locked = false;
|
||||
return c;
|
||||
}
|
||||
|
||||
rule_t *make_rule(void)
|
||||
{
|
||||
rule_t *r = malloc(sizeof(rule_t));
|
||||
r->floating = r->fullscreen = r->locked = r->centered = false;
|
||||
r->cause.class_name = r->cause.instance_name = NULL;
|
||||
r->effect.floating = r->effect.fullscreen = r->effect.locked = r->effect.centered = false;
|
||||
return r;
|
||||
}
|
||||
|
|
15
types.h
15
types.h
|
@ -60,6 +60,7 @@ typedef enum {
|
|||
typedef struct {
|
||||
xcb_window_t window;
|
||||
bool floating;
|
||||
bool transient;
|
||||
bool fullscreen;
|
||||
bool locked;
|
||||
} client_t;
|
||||
|
@ -87,15 +88,22 @@ struct desktop_t {
|
|||
desktop_t *next;
|
||||
};
|
||||
|
||||
typedef struct rule_t rule_t;
|
||||
struct rule_t {
|
||||
typedef struct {
|
||||
char *class_name;
|
||||
char *instance_name;
|
||||
char *win_title;
|
||||
} rule_cause_t;
|
||||
|
||||
typedef struct {
|
||||
bool floating;
|
||||
bool fullscreen;
|
||||
bool locked;
|
||||
bool centered;
|
||||
} rule_effect_t;
|
||||
|
||||
typedef struct rule_t rule_t;
|
||||
struct rule_t {
|
||||
rule_cause_t cause;
|
||||
rule_effect_t effect;
|
||||
rule_t *next;
|
||||
};
|
||||
|
||||
|
@ -107,5 +115,6 @@ typedef struct {
|
|||
node_t *make_node(void);
|
||||
desktop_t *make_desktop(void);
|
||||
client_t *make_client(xcb_window_t);
|
||||
rule_t *make_rule(void);
|
||||
|
||||
#endif
|
||||
|
|
1
utils.c
1
utils.c
|
@ -13,7 +13,6 @@
|
|||
|
||||
void die(const char *errstr, ...) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, errstr);
|
||||
vfprintf(stderr, errstr, ap);
|
||||
va_end(ap);
|
||||
|
|
Loading…
Add table
Reference in a new issue