mirror of
https://github.com/vale981/bspwm
synced 2025-03-06 02:01:42 -05:00
Initial approach for orphans adoption
This commit is contained in:
parent
fa82a462c0
commit
5ad12f917d
4 changed files with 95 additions and 71 deletions
17
bspwm.c
17
bspwm.c
|
@ -20,6 +20,7 @@
|
|||
#include "events.h"
|
||||
#include "common.h"
|
||||
#include "helpers.h"
|
||||
#include "window.h"
|
||||
#include "bspwm.h"
|
||||
#include "tree.h"
|
||||
#include "ewmh.h"
|
||||
|
@ -53,6 +54,21 @@ void ungrab_buttons(void)
|
|||
xcb_ungrab_button(dpy, XCB_BUTTON_INDEX_3, screen->root, button_modifier);
|
||||
}
|
||||
|
||||
void adopt_orphans(void)
|
||||
{
|
||||
xcb_query_tree_reply_t *qtr = xcb_query_tree_reply(dpy, xcb_query_tree(dpy, screen->root), NULL);
|
||||
if (qtr == NULL)
|
||||
return;
|
||||
int len = xcb_query_tree_children_length(qtr);
|
||||
if (len == 0)
|
||||
return;
|
||||
xcb_window_t *wins = xcb_query_tree_children(qtr);
|
||||
for (int i = 0; i < len; i++)
|
||||
manage_window(wins[i]);
|
||||
free(wins);
|
||||
free(qtr);
|
||||
}
|
||||
|
||||
void setup(void)
|
||||
{
|
||||
ewmh_init();
|
||||
|
@ -174,6 +190,7 @@ int main(int argc, char *argv[])
|
|||
run_autostart();
|
||||
grab_buttons();
|
||||
ewmh_update_wm_name();
|
||||
adopt_orphans();
|
||||
|
||||
while (running) {
|
||||
|
||||
|
|
73
events.c
73
events.c
|
@ -2,8 +2,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_icccm.h>
|
||||
#include <xcb/xcb_event.h>
|
||||
#include <xcb/xcb_icccm.h>
|
||||
#include "types.h"
|
||||
#include "bspwm.h"
|
||||
#include "settings.h"
|
||||
|
@ -58,76 +58,7 @@ void map_request(xcb_generic_event_t *evt)
|
|||
|
||||
PRINTF("map request %X\n", e->window);
|
||||
|
||||
xcb_window_t win = e->window;
|
||||
window_location_t loc;
|
||||
xcb_get_window_attributes_reply_t *wa = xcb_get_window_attributes_reply(dpy, xcb_get_window_attributes(dpy, win), NULL);
|
||||
uint8_t override_redirect = 0;
|
||||
|
||||
if (wa != NULL) {
|
||||
override_redirect = wa->override_redirect;
|
||||
free(wa);
|
||||
}
|
||||
|
||||
if (override_redirect || locate_window(win, &loc))
|
||||
return;
|
||||
|
||||
bool floating = false, transient = false, fullscreen = false, takes_focus = true, manage = true;
|
||||
|
||||
handle_rules(win, &floating, &transient, &fullscreen, &takes_focus, &manage);
|
||||
|
||||
if (!manage) {
|
||||
window_show(win);
|
||||
return;
|
||||
}
|
||||
|
||||
desktop_t *desk = mon->desk;
|
||||
client_t *c = make_client(win);
|
||||
update_floating_rectangle(c);
|
||||
|
||||
xcb_icccm_get_wm_class_reply_t reply;
|
||||
if (xcb_icccm_get_wm_class_reply(dpy, xcb_icccm_get_wm_class(dpy, win), &reply, NULL) == 1) {
|
||||
strncpy(c->class_name, reply.class_name, sizeof(c->class_name));
|
||||
xcb_icccm_get_wm_class_reply_wipe(&reply);
|
||||
}
|
||||
|
||||
if (c->transient)
|
||||
floating = true;
|
||||
|
||||
node_t *birth = make_node();
|
||||
birth->client = c;
|
||||
|
||||
if (floating)
|
||||
split_mode = MODE_MANUAL;
|
||||
|
||||
insert_node(desk, birth);
|
||||
|
||||
if (floating)
|
||||
toggle_floating(birth);
|
||||
|
||||
if (desk->focus != NULL && desk->focus->client->fullscreen)
|
||||
toggle_fullscreen(mon, desk->focus->client);
|
||||
|
||||
if (fullscreen)
|
||||
toggle_fullscreen(mon, birth->client);
|
||||
|
||||
c->transient = transient;
|
||||
|
||||
if (takes_focus)
|
||||
focus_node(mon, desk, birth, false);
|
||||
|
||||
fit_monitor(mon, birth->client);
|
||||
arrange(mon, desk);
|
||||
window_show(c->window);
|
||||
|
||||
if (takes_focus)
|
||||
xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME);
|
||||
|
||||
uint32_t values[] = {CLIENT_EVENT_MASK};
|
||||
xcb_change_window_attributes(dpy, c->window, XCB_CW_EVENT_MASK, values);
|
||||
|
||||
num_clients++;
|
||||
ewmh_set_wm_desktop(birth, desk);
|
||||
ewmh_update_client_list();
|
||||
manage_window(e->window);
|
||||
}
|
||||
|
||||
void configure_request(xcb_generic_event_t *evt)
|
||||
|
|
75
window.c
75
window.c
|
@ -4,11 +4,13 @@
|
|||
#include <string.h>
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_event.h>
|
||||
#include <xcb/xcb_icccm.h>
|
||||
#include "types.h"
|
||||
#include "tree.h"
|
||||
#include "bspwm.h"
|
||||
#include "settings.h"
|
||||
#include "ewmh.h"
|
||||
#include "rules.h"
|
||||
#include "window.h"
|
||||
|
||||
bool locate_window(xcb_window_t win, window_location_t *loc)
|
||||
|
@ -43,6 +45,79 @@ bool locate_desktop(char *name, desktop_location_t *loc)
|
|||
return false;
|
||||
}
|
||||
|
||||
void manage_window(xcb_window_t win)
|
||||
{
|
||||
window_location_t loc;
|
||||
xcb_get_window_attributes_reply_t *wa = xcb_get_window_attributes_reply(dpy, xcb_get_window_attributes(dpy, win), NULL);
|
||||
uint8_t override_redirect = 0;
|
||||
|
||||
if (wa != NULL) {
|
||||
override_redirect = wa->override_redirect;
|
||||
free(wa);
|
||||
}
|
||||
|
||||
if (override_redirect || locate_window(win, &loc))
|
||||
return;
|
||||
|
||||
bool floating = false, transient = false, fullscreen = false, takes_focus = true, manage = true;
|
||||
|
||||
handle_rules(win, &floating, &transient, &fullscreen, &takes_focus, &manage);
|
||||
|
||||
if (!manage) {
|
||||
window_show(win);
|
||||
return;
|
||||
}
|
||||
|
||||
desktop_t *desk = mon->desk;
|
||||
client_t *c = make_client(win);
|
||||
update_floating_rectangle(c);
|
||||
|
||||
xcb_icccm_get_wm_class_reply_t reply;
|
||||
if (xcb_icccm_get_wm_class_reply(dpy, xcb_icccm_get_wm_class(dpy, win), &reply, NULL) == 1) {
|
||||
strncpy(c->class_name, reply.class_name, sizeof(c->class_name));
|
||||
xcb_icccm_get_wm_class_reply_wipe(&reply);
|
||||
}
|
||||
|
||||
if (c->transient)
|
||||
floating = true;
|
||||
|
||||
node_t *birth = make_node();
|
||||
birth->client = c;
|
||||
|
||||
if (floating)
|
||||
split_mode = MODE_MANUAL;
|
||||
|
||||
insert_node(desk, birth);
|
||||
|
||||
if (floating)
|
||||
toggle_floating(birth);
|
||||
|
||||
if (desk->focus != NULL && desk->focus->client->fullscreen)
|
||||
toggle_fullscreen(mon, desk->focus->client);
|
||||
|
||||
if (fullscreen)
|
||||
toggle_fullscreen(mon, birth->client);
|
||||
|
||||
c->transient = transient;
|
||||
|
||||
if (takes_focus)
|
||||
focus_node(mon, desk, birth, false);
|
||||
|
||||
fit_monitor(mon, birth->client);
|
||||
arrange(mon, desk);
|
||||
window_show(c->window);
|
||||
|
||||
if (takes_focus)
|
||||
xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME);
|
||||
|
||||
uint32_t values[] = {CLIENT_EVENT_MASK};
|
||||
xcb_change_window_attributes(dpy, c->window, XCB_CW_EVENT_MASK, values);
|
||||
|
||||
num_clients++;
|
||||
ewmh_set_wm_desktop(birth, desk);
|
||||
ewmh_update_client_list();
|
||||
}
|
||||
|
||||
void window_draw_border(node_t *n, bool focused_window, bool focused_monitor)
|
||||
{
|
||||
if (n == NULL)
|
||||
|
|
1
window.h
1
window.h
|
@ -8,6 +8,7 @@
|
|||
|
||||
bool locate_window(xcb_window_t, window_location_t *);
|
||||
bool locate_desktop(char *, desktop_location_t *);
|
||||
void manage_window(xcb_window_t);
|
||||
void window_draw_border(node_t *, bool, bool);
|
||||
void window_close(node_t *);
|
||||
void window_kill(desktop_t *, node_t *);
|
||||
|
|
Loading…
Add table
Reference in a new issue