split up toggle_floating_mode into floating_enable and floating_disable

This commit is contained in:
Michael Stapelberg 2010-06-28 21:40:17 +02:00
parent 285692c92c
commit 69e1975e29
2 changed files with 79 additions and 57 deletions

View File

@ -28,9 +28,23 @@ typedef enum { BORDER_LEFT = (1 << 0),
BORDER_BOTTOM = (1 << 3)} border_t; BORDER_BOTTOM = (1 << 3)} border_t;
/** /**
* Enters floating mode for the given client. Correctly takes care of the * Enables floating mode for the given container by detaching it from its
* position/size (separately stored for tiling/floating mode) and * parent, creating a new container around it and storing this container in the
* repositions/resizes/redecorates the client. * floating_windows list of the workspace.
*
*/
void floating_enable(Con *con, bool automatic);
/**
* Disables floating mode for the given container by re-attaching the container
* to its old parent.
*
*/
void floating_disable(Con *con, bool automatic);
/**
* Calls floating_enable() for tiling containers and floating_disable() for
* floating containers.
* *
* If the automatic flag is set to true, this was an automatic update by a * If the automatic flag is set to true, this was an automatic update by a
* change of the window class from the application which can be overwritten by * change of the window class from the application which can be overwritten by

View File

@ -1,5 +1,5 @@
/* /*
* vim:ts=8:expandtab * vim:ts=4:sw=4:expandtab
* *
* i3 - an improved dynamic tiling window manager * i3 - an improved dynamic tiling window manager
* *
@ -16,40 +16,7 @@
extern xcb_connection_t *conn; extern xcb_connection_t *conn;
/* void floating_enable(Con *con, bool automatic) {
* Toggles floating mode for the given container.
*
* If the automatic flag is set to true, this was an automatic update by a change of the
* window class from the application which can be overwritten by the user.
*
*/
void toggle_floating_mode(Con *con, bool automatic) {
//i3Font *font = load_font(conn, config.font);
/* see if the client is already floating */
if (con_is_floating(con)) {
LOG("already floating, re-setting to tiling\n");
assert(con->old_parent != NULL);
/* 1: detach from parent container */
TAILQ_REMOVE(&(con->parent->nodes_head), con, nodes);
TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
/* 2: kill parent container */
TAILQ_REMOVE(&(con->parent->parent->floating_head), con->parent, floating_windows);
TAILQ_REMOVE(&(con->parent->parent->focus_head), con->parent, focused);
tree_close(con->parent, false);
/* 3: re-attach to previous parent */
con->parent = con->old_parent;
TAILQ_INSERT_TAIL(&(con->parent->nodes_head), con, nodes);
TAILQ_INSERT_TAIL(&(con->parent->focus_head), con, focused);
con->floating = FLOATING_USER_OFF;
return;
}
/* 1: detach the container from its parent */ /* 1: detach the container from its parent */
/* TODO: refactor this with tree_close() */ /* TODO: refactor this with tree_close() */
TAILQ_REMOVE(&(con->parent->nodes_head), con, nodes); TAILQ_REMOVE(&(con->parent->nodes_head), con, nodes);
@ -85,7 +52,48 @@ void toggle_floating_mode(Con *con, bool automatic) {
nc->rect.y = 400; nc->rect.y = 400;
TAILQ_INSERT_TAIL(&(nc->nodes_head), con, nodes); TAILQ_INSERT_TAIL(&(nc->nodes_head), con, nodes);
TAILQ_INSERT_TAIL(&(nc->focus_head), con, focused); TAILQ_INSERT_TAIL(&(nc->focus_head), con, focused);
}
void floating_disable(Con *con, bool automatic) {
assert(con->old_parent != NULL);
/* 1: detach from parent container */
TAILQ_REMOVE(&(con->parent->nodes_head), con, nodes);
TAILQ_REMOVE(&(con->parent->focus_head), con, focused);
/* 2: kill parent container */
TAILQ_REMOVE(&(con->parent->parent->floating_head), con->parent, floating_windows);
TAILQ_REMOVE(&(con->parent->parent->focus_head), con->parent, focused);
tree_close(con->parent, false);
/* 3: re-attach to previous parent */
con->parent = con->old_parent;
TAILQ_INSERT_TAIL(&(con->parent->nodes_head), con, nodes);
TAILQ_INSERT_TAIL(&(con->parent->focus_head), con, focused);
con->floating = FLOATING_USER_OFF;
}
/*
* Toggles floating mode for the given container.
*
* If the automatic flag is set to true, this was an automatic update by a change of the
* window class from the application which can be overwritten by the user.
*
*/
void toggle_floating_mode(Con *con, bool automatic) {
//i3Font *font = load_font(conn, config.font);
/* see if the client is already floating */
if (con_is_floating(con)) {
LOG("already floating, re-setting to tiling\n");
floating_disable(con, automatic);
return;
}
floating_enable(con, automatic);
#if 0 #if 0