Added config key for default orientation of containers (new_container_orientation) and added support in randr.c for automatically changing the orientation when user does a xrandr rotate.

next
Simon Kampe 2011-03-16 11:56:51 +01:00 committed by Michael Stapelberg
parent b484ed5f9d
commit 2f992f5c0e
8 changed files with 86 additions and 3 deletions

View File

@ -19,7 +19,13 @@ bindsym Mod1+Return exec /usr/bin/urxvt
# Start dmenu (Mod1+p)
bindsym Mod1+p exec /usr/bin/dmenu_run
# Default orientation
new_container_orientation horizontal
# Horizontal orientation
bindsym Mod1+h split h
# Vertical orientation
bindsym Mod1+v split v
# Fullscreen (Mod1+f)

View File

@ -95,6 +95,9 @@ struct Config {
int container_stack_limit;
int container_stack_limit_value;
/** Default orientation for new containers */
int default_orientation;
/** By default, focus follows mouse. If the user explicitly wants to
* turn this off (and instead rely only on the keyboard for changing
* focus), we allow him to do this with this relatively special option.

View File

@ -92,6 +92,10 @@ set[^\n]* { return TOKCOMMENT; }
ipc-socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
ipc_socket { BEGIN(BIND_AWS_COND); return TOKIPCSOCKET; }
restart_state { BEGIN(BIND_AWS_COND); return TOKRESTARTSTATE; }
new_container_orientation { return TOK_ORIENTATION; }
horizontal { return TOK_HORIZ; }
vertical { return TOK_VERT; }
auto { return TOK_AUTO; }
new_container { return TOKNEWCONTAINER; }
new_window { return TOKNEWWINDOW; }
normal { return TOK_NORMAL; }

View File

@ -224,6 +224,10 @@ void parse_file(const char *f) {
%token TOKCOLOR
%token TOKARROW "→"
%token TOKMODE "mode"
%token TOK_ORIENTATION "new_container_orientation"
%token TOK_HORIZ "horizontal"
%token TOK_VERT "vertical"
%token TOK_AUTO "auto"
%token TOKNEWCONTAINER "new_container"
%token TOKNEWWINDOW "new_window"
%token TOK_NORMAL "normal"
@ -249,6 +253,7 @@ line:
bindline
| mode
| floating_modifier
| orientation
| new_container
| new_window
| focus_follows_mouse
@ -373,6 +378,20 @@ floating_modifier:
}
;
orientation:
TOK_ORIENTATION WHITESPACE direction
{
DLOG("New containers should start with split direction %d\n", $<number>3);
config.default_orientation = $<number>3;
}
;
direction:
TOK_HORIZ { $<number>$ = HORIZ; }
| TOK_VERT { $<number>$ = VERT; }
| TOK_AUTO { $<number>$ = NO_ORIENTATION; }
;
new_container:
TOKNEWCONTAINER WHITESPACE TOKCONTAINERMODE
{

View File

@ -794,7 +794,11 @@ void con_set_layout(Con *con, int layout) {
/* 3: While the layout is irrelevant in stacked/tabbed mode, it needs
* to be set. Otherwise, this con will not be interpreted as a split
* container. */
new->orientation = HORIZ;
if (config.default_orientation == NO_ORIENTATION) {
new->orientation = (con->rect.height > con->rect.width) ? VERT : HORIZ;
} else {
new->orientation = config.default_orientation;
}
Con *old_focused = TAILQ_FIRST(&(con->focus_head));
if (old_focused == TAILQ_END(&(con->focus_head)))

View File

@ -331,6 +331,8 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath,
INIT_COLOR(config.bar.urgent, "#2f343a", "#900000", "#ffffff");
config.default_border = BS_NORMAL;
/* Set default_orientation to NO_ORIENTATION for auto orientation. */
config.default_orientation = NO_ORIENTATION;
parse_configuration(override_configpath);

View File

@ -361,7 +361,17 @@ void output_init_con(Output *output) {
free(name);
ws->fullscreen_mode = CF_OUTPUT;
ws->orientation = HORIZ;
/* If default_orientation is set to NO_ORIENTATION we determine
* orientation depending on output resolution. */
if (config.default_orientation == NO_ORIENTATION) {
ws->orientation = (output->rect.height > output->rect.width) ? VERT : HORIZ;
DLOG("Auto orientation. Workspace size set to (%d,%d), setting orientation to %d.\n",
output->rect.width, output->rect.height, ws->orientation);
} else {
ws->orientation = config.default_orientation;
}
/* TODO: Set focus in main.c */
con_focus(ws);
@ -384,6 +394,30 @@ static void output_change_mode(xcb_connection_t *conn, Output *output) {
DLOG("Output mode changed, updating rect\n");
assert(output->con != NULL);
output->con->rect = output->rect;
Con *current,*workspace,*child;
/* Point current to the container of the workspaces */
current = output->con->nodes_head.tqh_first->nodes.tqe_next;
/* If default_orientation is NO_ORIENTATION, we change the orientation of
* the workspaces and their childs depending on output resolution. This is
* only done for workspaces with maximum one child. */
if (config.default_orientation == NO_ORIENTATION) {
TAILQ_FOREACH(workspace, &(current->nodes_head), nodes) {
/* Check if this workspace has <= 1 childs. */
child = workspace->nodes_head.tqh_first;
if (child != NULL)
if (child->nodes.tqe_next == NULL) {
workspace->orientation = (output->rect.height > output->rect.width) ? VERT : HORIZ;
DLOG("Setting workspace [%d,%s]'s orientation to %d.\n", workspace->num, workspace->name, workspace->orientation);
child->orientation = workspace->orientation;
DLOG("Setting child [%d,%s]'s orientation to %d.\n", child->num, child->name, child->orientation);
}
}
}
#if 0
Rect bar_rect = {output->rect.x,
output->rect.y + output->rect.height - (font->height + 6),

View File

@ -59,7 +59,18 @@ Con *workspace_get(const char *num, bool *created) {
workspace->num = -1;
else workspace->num = parsed_num;
LOG("num = %d\n", workspace->num);
workspace->orientation = HORIZ;
/* If default_orientation is set to NO_ORIENTATION we
* determine workspace orientation from workspace size.
* Otherwise we just set the orientation to default_orientation. */
if (config.default_orientation == NO_ORIENTATION) {
workspace->orientation = (output->rect.height > output->rect.width) ? VERT : HORIZ;
DLOG("Auto orientation. Output resolution set to (%d,%d), setting orientation to %d.\n",
workspace->rect.width, workspace->rect.height, workspace->orientation);
} else {
workspace->orientation = config.default_orientation;
}
con_attach(workspace, content, false);
ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"init\"}");