mirror of
https://github.com/vale981/bspwm
synced 2025-03-06 02:01:42 -05:00
Map requests slowly being taken care of
This commit is contained in:
parent
25750a9f80
commit
c81516c0dc
7 changed files with 115 additions and 28 deletions
7
bspwm.c
7
bspwm.c
|
@ -97,6 +97,13 @@ void setup(int default_screen)
|
||||||
/* xcb_change_property(dpy, XCB_PROP_MODE_REPLACE, screen->root, netatoms[NET_SUPPORTED], XCB_ATOM_ATOM, 32, NET_COUNT, netatoms); */
|
/* xcb_change_property(dpy, XCB_PROP_MODE_REPLACE, screen->root, netatoms[NET_SUPPORTED], XCB_ATOM_ATOM, 32, NET_COUNT, netatoms); */
|
||||||
xcb_ewmh_set_supported(&ewmh, default_screen, LENGTH(net_atoms), net_atoms);
|
xcb_ewmh_set_supported(&ewmh, default_screen, LENGTH(net_atoms), net_atoms);
|
||||||
xcb_ewmh_set_wm_name(&ewmh, screen->root, LENGTH(WM_NAME), WM_NAME);
|
xcb_ewmh_set_wm_name(&ewmh, screen->root, LENGTH(WM_NAME), WM_NAME);
|
||||||
|
|
||||||
|
desk = make_desktop();
|
||||||
|
last_desk = NULL;
|
||||||
|
desk_head = desk;
|
||||||
|
desk_tail = desk;
|
||||||
|
|
||||||
|
split_mode = MODE_AUTOMATIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
|
58
events.c
58
events.c
|
@ -7,6 +7,7 @@
|
||||||
#include "bspwm.h"
|
#include "bspwm.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "events.h"
|
#include "events.h"
|
||||||
|
#include "tree.h"
|
||||||
|
|
||||||
void handle_event(xcb_generic_event_t *evt)
|
void handle_event(xcb_generic_event_t *evt)
|
||||||
{
|
{
|
||||||
|
@ -45,19 +46,72 @@ void map_request(xcb_generic_event_t *evt)
|
||||||
if ((wa != NULL && wa->override_redirect) || win_to_node(win) != NULL)
|
if ((wa != NULL && wa->override_redirect) || win_to_node(win) != NULL)
|
||||||
return;
|
return;
|
||||||
free(wa);
|
free(wa);
|
||||||
|
bool takes_focus = true;
|
||||||
client_t *c = make_client();
|
client_t *c = make_client();
|
||||||
c->window = win;
|
c->window = win;
|
||||||
num_clients++;
|
num_clients++;
|
||||||
node_t *focus = desk->focus;
|
node_t *focus = desk->focus;
|
||||||
|
node_t *birth = make_node();
|
||||||
|
birth->client = c;
|
||||||
|
|
||||||
if (focus == NULL) {
|
if (focus == NULL) {
|
||||||
focus = make_node();
|
desk->root = desk->view = desk->head = desk->tail = birth;
|
||||||
focus->client = c;
|
|
||||||
} else {
|
} else {
|
||||||
|
node_t *dad = make_node();
|
||||||
|
birth->parent = dad;
|
||||||
switch (split_mode) {
|
switch (split_mode) {
|
||||||
case MODE_AUTOMATIC:
|
case MODE_AUTOMATIC:
|
||||||
|
if (focus->parent == NULL) {
|
||||||
|
} else {
|
||||||
|
node_t *grandpa = focus->parent->parent;
|
||||||
|
dad->parent = grandpa;
|
||||||
|
if (grandpa != NULL) {
|
||||||
|
if (is_first_child(focus->parent))
|
||||||
|
grandpa->first_child = dad;
|
||||||
|
else
|
||||||
|
grandpa->second_child = dad;
|
||||||
|
}
|
||||||
|
if (is_first_child(focus)) {
|
||||||
|
dad->first_child = birth;
|
||||||
|
dad->second_child = focus->parent;
|
||||||
|
} else {
|
||||||
|
dad->first_child = focus->parent;
|
||||||
|
dad->second_child = birth;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MODE_MANUAL:
|
case MODE_MANUAL:
|
||||||
|
focus->parent = dad;
|
||||||
|
switch (split_dir) {
|
||||||
|
case DIR_LEFT:
|
||||||
|
dad->split_type = TYPE_VERTICAL;
|
||||||
|
dad->first_child = birth;
|
||||||
|
dad->second_child = focus;
|
||||||
|
break;
|
||||||
|
case DIR_RIGHT:
|
||||||
|
dad->split_type = TYPE_VERTICAL;
|
||||||
|
dad->first_child = focus;
|
||||||
|
dad->second_child = birth;
|
||||||
|
break;
|
||||||
|
case DIR_UP:
|
||||||
|
dad->split_type = TYPE_HORIZONTAL;
|
||||||
|
dad->first_child = birth;
|
||||||
|
dad->second_child = focus;
|
||||||
|
break;
|
||||||
|
case DIR_DOWN:
|
||||||
|
dad->split_type = TYPE_HORIZONTAL;
|
||||||
|
dad->first_child = focus;
|
||||||
|
dad->second_child = birth;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (desk->root == focus)
|
||||||
|
desk->root = dad;
|
||||||
|
if (desk->view == focus)
|
||||||
|
desk->view = dad;
|
||||||
|
split_mode = MODE_AUTOMATIC;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (takes_focus)
|
||||||
|
desk->focus = birth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
tree.c
6
tree.c
|
@ -11,6 +11,12 @@ bool is_leaf(node_t *n)
|
||||||
return (n != NULL && n->first_child == NULL && n->second_child == NULL);
|
return (n != NULL && n->first_child == NULL && n->second_child == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_first_child(node_t *n)
|
||||||
|
{
|
||||||
|
return (n != NULL && n->parent != NULL && n->parent->first_child == n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void change_split_ratio(node_t *n, value_change_t chg) {
|
void change_split_ratio(node_t *n, value_change_t chg) {
|
||||||
n->split_ratio = pow(n->split_ratio, (chg == CHANGE_INCREASE ? INC_EXP : DEC_EXP));
|
n->split_ratio = pow(n->split_ratio, (chg == CHANGE_INCREASE ? INC_EXP : DEC_EXP));
|
||||||
}
|
}
|
||||||
|
|
1
tree.h
1
tree.h
|
@ -5,6 +5,7 @@
|
||||||
#define DEC_EXP 1.1
|
#define DEC_EXP 1.1
|
||||||
|
|
||||||
bool is_leaf(node_t *);
|
bool is_leaf(node_t *);
|
||||||
|
bool is_first_child(node_t *n);
|
||||||
void change_split_ratio(node_t *, value_change_t);
|
void change_split_ratio(node_t *, value_change_t);
|
||||||
node_t *first_extrema(node_t *);
|
node_t *first_extrema(node_t *);
|
||||||
node_t *second_extrema(node_t *);
|
node_t *second_extrema(node_t *);
|
||||||
|
|
8
types.c
8
types.c
|
@ -1,4 +1,7 @@
|
||||||
|
#define _BSD_SOURCE
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <xcb/xcb_event.h>
|
#include <xcb/xcb_event.h>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
@ -8,13 +11,16 @@ node_t *make_node(void)
|
||||||
node_t *n = malloc(sizeof(node_t));
|
node_t *n = malloc(sizeof(node_t));
|
||||||
n->parent = n->first_child = n->second_child = n->next_leaf = n->prev_leaf = NULL;
|
n->parent = n->first_child = n->second_child = n->next_leaf = n->prev_leaf = NULL;
|
||||||
n->client = NULL;
|
n->client = NULL;
|
||||||
|
n->vacant = false;
|
||||||
|
n->split_ratio = SPLIT_RATIO;
|
||||||
|
n->split_type = TYPE_VERTICAL;
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
desktop_t *make_desktop(void)
|
desktop_t *make_desktop(void)
|
||||||
{
|
{
|
||||||
desktop_t *d = malloc(sizeof(desktop_t));
|
desktop_t *d = malloc(sizeof(desktop_t));
|
||||||
d->name = NULL;
|
d->name = strdup(DESK_NAME);
|
||||||
d->layout = LAYOUT_TILED;
|
d->layout = LAYOUT_TILED;
|
||||||
d->prev = d->next = NULL;
|
d->prev = d->next = NULL;
|
||||||
d->root = d->view = d->focus = d->last_focus = d->head = d->tail = NULL;
|
d->root = d->view = d->focus = d->last_focus = d->head = d->tail = NULL;
|
||||||
|
|
23
types.h
23
types.h
|
@ -5,7 +5,8 @@
|
||||||
#include <xcb/xcb_event.h>
|
#include <xcb/xcb_event.h>
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
|
||||||
#define DEFAULT_NAME "one"
|
#define SPLIT_RATIO 0.5
|
||||||
|
#define DESK_NAME "One"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TYPE_HORIZONTAL,
|
TYPE_HORIZONTAL,
|
||||||
|
@ -78,16 +79,6 @@ struct node_t {
|
||||||
node_t *next_leaf;
|
node_t *next_leaf;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct rule_t rule_t;
|
|
||||||
struct rule_t {
|
|
||||||
char *class_name;
|
|
||||||
char *desk_name;
|
|
||||||
bool floating;
|
|
||||||
bool fullscreen;
|
|
||||||
bool locked;
|
|
||||||
rule_t *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct desktop_t desktop_t;
|
typedef struct desktop_t desktop_t;
|
||||||
struct desktop_t {
|
struct desktop_t {
|
||||||
char *name;
|
char *name;
|
||||||
|
@ -102,6 +93,16 @@ struct desktop_t {
|
||||||
desktop_t *next;
|
desktop_t *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct rule_t rule_t;
|
||||||
|
struct rule_t {
|
||||||
|
char *class_name;
|
||||||
|
char *win_title;
|
||||||
|
bool floating;
|
||||||
|
bool fullscreen;
|
||||||
|
bool locked;
|
||||||
|
rule_t *next;
|
||||||
|
};
|
||||||
|
|
||||||
node_t *make_node(void);
|
node_t *make_node(void);
|
||||||
desktop_t *make_desktop(void);
|
desktop_t *make_desktop(void);
|
||||||
client_t *make_client(void);
|
client_t *make_client(void);
|
||||||
|
|
38
utils.c
38
utils.c
|
@ -1,6 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <string.h>
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <xcb/xcb_event.h>
|
#include <xcb/xcb_event.h>
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
|
@ -50,20 +51,31 @@ uint32_t get_color(char *col)
|
||||||
{
|
{
|
||||||
xcb_colormap_t map = screen->default_colormap;
|
xcb_colormap_t map = screen->default_colormap;
|
||||||
xcb_alloc_color_reply_t *rpl;
|
xcb_alloc_color_reply_t *rpl;
|
||||||
|
xcb_alloc_named_color_reply_t *rpln;
|
||||||
uint32_t rgb, pxl;
|
uint32_t rgb, pxl;
|
||||||
uint16_t r, g, b;
|
uint16_t r, g, b;
|
||||||
|
|
||||||
rgb = color_pixel(col);
|
if (col[0] == '#') {
|
||||||
r = rgb >> 16;
|
rgb = color_pixel(col);
|
||||||
g = rgb >> 8 & 0xFF;
|
r = rgb >> 16;
|
||||||
b = rgb & 0xFF;
|
g = rgb >> 8 & 0xFF;
|
||||||
rpl = xcb_alloc_color_reply(dpy, xcb_alloc_color(dpy, map, r * 257, g * 257, b * 257), NULL);
|
b = rgb & 0xFF;
|
||||||
|
rpl = xcb_alloc_color_reply(dpy, xcb_alloc_color(dpy, map, r * 257, g * 257, b * 257), NULL);
|
||||||
|
if (rpl != NULL) {
|
||||||
|
pxl = rpl->pixel;
|
||||||
|
free(rpl);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
rpln = xcb_alloc_named_color_reply(dpy, xcb_alloc_named_color(dpy, map, strlen(col), col), NULL);
|
||||||
|
if (rpln != NULL) {
|
||||||
|
pxl = rpln->pixel;
|
||||||
|
free(rpln);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!rpl)
|
/* if (!rpl) */
|
||||||
die("error: cannot allocate color '%s'\n", col);
|
/* die("error: cannot allocate color '%s'\n", col); */
|
||||||
|
|
||||||
pxl = rpl->pixel;
|
|
||||||
free(rpl);
|
|
||||||
return pxl;
|
return pxl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,19 +149,19 @@ void draw_triple_border(node_t *n, uint32_t main_border_color_pxl)
|
||||||
case DIR_UP:
|
case DIR_UP:
|
||||||
presel_rectangles[0] = (xcb_rectangle_t) {width, 0, 2 * border_width, split_pos};
|
presel_rectangles[0] = (xcb_rectangle_t) {width, 0, 2 * border_width, split_pos};
|
||||||
presel_rectangles[1] = (xcb_rectangle_t) {0, height + border_width, full_width, border_width};
|
presel_rectangles[1] = (xcb_rectangle_t) {0, height + border_width, full_width, border_width};
|
||||||
break;
|
break;
|
||||||
case DIR_DOWN:
|
case DIR_DOWN:
|
||||||
presel_rectangles[0] = (xcb_rectangle_t) {width, split_pos + 1, 2 * border_width, height + border_width - (split_pos + 1)};
|
presel_rectangles[0] = (xcb_rectangle_t) {width, split_pos + 1, 2 * border_width, height + border_width - (split_pos + 1)};
|
||||||
presel_rectangles[1] = (xcb_rectangle_t) {0, height + border_width, full_width, border_width};
|
presel_rectangles[1] = (xcb_rectangle_t) {0, height + border_width, full_width, border_width};
|
||||||
break;
|
break;
|
||||||
case DIR_LEFT:
|
case DIR_LEFT:
|
||||||
presel_rectangles[0] = (xcb_rectangle_t) {0, height, split_pos, 2 * border_width};
|
presel_rectangles[0] = (xcb_rectangle_t) {0, height, split_pos, 2 * border_width};
|
||||||
presel_rectangles[1] = (xcb_rectangle_t) {width + border_width, 0, border_width, full_height};
|
presel_rectangles[1] = (xcb_rectangle_t) {width + border_width, 0, border_width, full_height};
|
||||||
break;
|
break;
|
||||||
case DIR_RIGHT:
|
case DIR_RIGHT:
|
||||||
presel_rectangles[0] = (xcb_rectangle_t) {split_pos + 1, height, width + border_width - (split_pos + 1), 2 * border_width};
|
presel_rectangles[0] = (xcb_rectangle_t) {split_pos + 1, height, width + border_width - (split_pos + 1), 2 * border_width};
|
||||||
presel_rectangles[1] = (xcb_rectangle_t) {width, 0, border_width, full_height};
|
presel_rectangles[1] = (xcb_rectangle_t) {width, 0, border_width, full_height};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &presel_border_color_pxl);
|
xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &presel_border_color_pxl);
|
||||||
xcb_poly_fill_rectangle(dpy, pix, gc, LENGTH(presel_rectangles), presel_rectangles);
|
xcb_poly_fill_rectangle(dpy, pix, gc, LENGTH(presel_rectangles), presel_rectangles);
|
||||||
|
|
Loading…
Add table
Reference in a new issue