recognize dock windows (and support matching them)

This commit is contained in:
Michael Stapelberg 2010-08-15 12:18:27 +02:00
parent 0411299e4c
commit 160c12ed9a
6 changed files with 49 additions and 5 deletions

View File

@ -228,6 +228,9 @@ struct Window {
/** Whether the application used _NET_WM_NAME */ /** Whether the application used _NET_WM_NAME */
bool uses_net_wm_name; bool uses_net_wm_name;
/** Whether the window says it is a dock window */
bool dock;
}; };
struct Match { struct Match {
@ -239,6 +242,7 @@ struct Match {
char *class; char *class;
char *instance; char *instance;
char *mark; char *mark;
int dock;
xcb_window_t id; xcb_window_t id;
Con *con_id; Con *con_id;
enum { M_ANY = 0, M_TILING, M_FLOATING } floating; enum { M_ANY = 0, M_TILING, M_FLOATING } floating;

View File

@ -1,6 +1,14 @@
#ifndef _MATCH_H #ifndef _MATCH_H
#define _MATCH_H #define _MATCH_H
/*
* Initializes the Match data structure. This function is necessary because the
* members representing boolean values (like dock) need to be initialized with
* -1 instead of 0.
*
*/
void match_init(Match *match);
/** /**
* Check if a match is empty. This is necessary while parsing commands to see * Check if a match is empty. This is necessary while parsing commands to see
* whether the user specified a match at all. * whether the user specified a match at all.

View File

@ -1,3 +1,7 @@
/*
* vim:ts=4:sw=4:expandtab
*
*/
#include <yajl/yajl_common.h> #include <yajl/yajl_common.h>
#include <yajl/yajl_gen.h> #include <yajl/yajl_gen.h>
#include <yajl/yajl_parse.h> #include <yajl/yajl_parse.h>
@ -16,7 +20,8 @@ static int json_start_map(void *ctx) {
LOG("start of map\n"); LOG("start of map\n");
if (parsing_swallows) { if (parsing_swallows) {
LOG("TODO: create new swallow\n"); LOG("TODO: create new swallow\n");
current_swallow = scalloc(sizeof(Match)); current_swallow = smalloc(sizeof(Match));
match_init(current_swallow);
TAILQ_INSERT_TAIL(&(json_node->swallow_head), current_swallow, matches); TAILQ_INSERT_TAIL(&(json_node->swallow_head), current_swallow, matches);
} else { } else {
if (!parsing_rect) if (!parsing_rect)
@ -104,6 +109,9 @@ static int json_int(void *ctx, long val) {
if (strcasecmp(last_key, "id") == 0) { if (strcasecmp(last_key, "id") == 0) {
current_swallow->id = val; current_swallow->id = val;
} }
if (strcasecmp(last_key, "dock") == 0) {
current_swallow->dock = true;
}
} }
return 1; return 1;

View File

@ -296,7 +296,9 @@ int main(int argc, char *argv[]) {
/* proof-of-concept for assignments */ /* proof-of-concept for assignments */
Con *ws = workspace_get("3"); Con *ws = workspace_get("3");
Match *current_swallow = scalloc(sizeof(Match)); Match *current_swallow = smalloc(sizeof(Match));
match_init(current_swallow);
TAILQ_INSERT_TAIL(&(ws->swallow_head), current_swallow, matches); TAILQ_INSERT_TAIL(&(ws->swallow_head), current_swallow, matches);
current_swallow->insert_where = M_ACTIVE; current_swallow->insert_where = M_ACTIVE;

View File

@ -145,6 +145,13 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
window_update_name_legacy(cwindow, xcb_get_property_reply(conn, title_cookie, NULL)); window_update_name_legacy(cwindow, xcb_get_property_reply(conn, title_cookie, NULL));
window_update_name(cwindow, xcb_get_property_reply(conn, utf8_title_cookie, NULL)); window_update_name(cwindow, xcb_get_property_reply(conn, utf8_title_cookie, NULL));
xcb_get_property_reply_t *reply = xcb_get_property_reply(conn, wm_type_cookie, NULL);
if (xcb_reply_contains_atom(reply, atoms[_NET_WM_WINDOW_TYPE_DOCK])) {
cwindow->dock = true;
LOG("this window is a dock\n");
}
Con *nc; Con *nc;
Match *match; Match *match;
@ -175,9 +182,6 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
nc->window = cwindow; nc->window = cwindow;
x_reinit(nc); x_reinit(nc);
xcb_get_property_reply_t *reply = xcb_get_property_reply(conn, wm_type_cookie, NULL);
if (xcb_reply_contains_atom(reply, atoms[_NET_WM_WINDOW_TYPE_DOCK]))
LOG("this window is a dock\n");
/* set floating if necessary */ /* set floating if necessary */
if (xcb_reply_contains_atom(reply, atoms[_NET_WM_WINDOW_TYPE_DIALOG]) || if (xcb_reply_contains_atom(reply, atoms[_NET_WM_WINDOW_TYPE_DIALOG]) ||

View File

@ -14,6 +14,17 @@
#include "all.h" #include "all.h"
/*
* Initializes the Match data structure. This function is necessary because the
* members representing boolean values (like dock) need to be initialized with
* -1 instead of 0.
*
*/
void match_init(Match *match) {
memset(match, 0, sizeof(Match));
match->dock = -1;
}
/* /*
* Check if a match is empty. This is necessary while parsing commands to see * Check if a match is empty. This is necessary while parsing commands to see
* whether the user specified a match at all. * whether the user specified a match at all.
@ -30,6 +41,7 @@ bool match_is_empty(Match *match) {
match->instance == NULL && match->instance == NULL &&
match->id == XCB_NONE && match->id == XCB_NONE &&
match->con_id == NULL && match->con_id == NULL &&
match->dock == -1 &&
match->floating == M_ANY); match->floating == M_ANY);
} }
@ -54,6 +66,12 @@ bool match_matches_window(Match *match, i3Window *window) {
return true; return true;
} }
LOG("match->dock = %d, window->dock = %d\n", match->dock, window->dock);
if (match->dock != -1 && window->dock == match->dock) {
LOG("match made by dock\n");
return true;
}
LOG("window %d (%s) could not be matched\n", window->id, window->class_class); LOG("window %d (%s) could not be matched\n", window->id, window->class_class);
return false; return false;