35 DLOG(
"Auto orientation. Workspace size set to (%d,%d), setting layout to %d.\n",
49 Con *output, *workspace = NULL;
54 if (workspace == NULL) {
55 LOG(
"Creating new workspace \"%s\"\n", num);
67 if (strcmp(assignment->
name, num) == 0) {
68 DLOG(
"Found workspace name assignment to output \"%s\"\n", assignment->
output);
72 DLOG(
"Found workspace number assignment to output \"%s\"\n", assignment->
output);
78 LOG(
"got output %p with content %p\n", output, content);
81 workspace =
con_new(NULL, NULL);
83 sasprintf(&name,
"[i3 con] workspace %s", num);
86 workspace->
type = CT_WORKSPACE;
90 workspace->
num = parsed_num;
91 LOG(
"num = %d\n", workspace->
num);
93 workspace->
parent = content;
105 }
else if (created != NULL) {
130 if (strlen(bind->
command) < strlen(
"workspace ") ||
131 strncasecmp(bind->
command,
"workspace", strlen(
"workspace")) != 0)
134 const char *target = bind->
command + strlen(
"workspace ");
135 while (*target ==
' ' || *target ==
'\t')
142 if (strncasecmp(target,
"next", strlen(
"next")) == 0 ||
143 strncasecmp(target,
"prev", strlen(
"prev")) == 0 ||
144 strncasecmp(target,
"next_on_output", strlen(
"next_on_output")) == 0 ||
145 strncasecmp(target,
"prev_on_output", strlen(
"prev_on_output")) == 0 ||
146 strncasecmp(target,
"number", strlen(
"number")) == 0 ||
147 strncasecmp(target,
"back_and_forth", strlen(
"back_and_forth")) == 0 ||
148 strncasecmp(target,
"current", strlen(
"current")) == 0)
151 if (target_name == NULL)
153 if (strncasecmp(target_name,
"__", strlen(
"__")) == 0) {
154 LOG(
"Cannot create workspace \"%s\". Names starting with __ are i3-internal.\n", target);
158 DLOG(
"Saving workspace name \"%s\"\n", target_name);
179 ws->
type = CT_WORKSPACE;
187 bool assigned =
false;
190 if (strcmp(assignment->
name, target_name) != 0 ||
191 strcmp(assignment->
output, output->
name) == 0)
204 exists = (current != NULL);
210 LOG(
"Used number %d for workspace with name %s\n", ws->
num, ws->
name);
218 DLOG(
"Getting next unused workspace by number\n");
228 exists = (current != NULL);
230 DLOG(
"result for ws %d: exists = %d\n", c, exists);
259 LOG(
"workspace visible? fs = %p, ws = %p\n", fs, ws);
271 if (current != exclude &&
273 current->
window != NULL &&
282 TAILQ_FOREACH(current, &(con->floating_head), floating_windows) {
283 if (current != exclude &&
285 current->
window != NULL &&
315 LOG(
"Ah, this one is sticky: %s / %p\n", current->
name, current);
321 LOG(
"No window found for this sticky group\n");
334 LOG(
"re-assigned window from src %p to dest %p\n", src, current);
337 TAILQ_FOREACH(current, &(con->floating_head), floating_windows)
354 DLOG(
"Resetting urgency flag of con %p by timer\n", con);
364 Con *current, *old = NULL;
383 if (workspace == current) {
384 DLOG(
"Not switching, already there.\n");
404 DLOG(
"switching to %p / %s\n", workspace, workspace->
name);
424 DLOG(
"Deferring reset of urgency flag of con %p on newly shown workspace %p\n",
433 DLOG(
"Resetting urgency timer of con %p on workspace %p\n",
442 DLOG(
"old = %p / %s\n", old, (old ? old->
name :
"(null)"));
451 LOG(
"Closing old workspace (%p / %s), it is empty\n", old, old->
name);
455 const unsigned char *payload;
457 y(get_buf, &payload, &length);
458 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE, (
const char *)payload);
474 if (old_output != new_output) {
509 Con *next = NULL, *first = NULL, *first_opposite = NULL;
512 if (current->
num == -1) {
514 if ((next =
TAILQ_NEXT(current, nodes)) != NULL)
516 bool found_current =
false;
522 if (child->type != CT_WORKSPACE)
526 if (!first_opposite || (child->num != -1 && child->num < first_opposite->num))
527 first_opposite = child;
528 if (child == current) {
529 found_current =
true;
530 }
else if (child->num == -1 && found_current) {
543 if (child->type != CT_WORKSPACE)
545 if (!first || (child->num != -1 && child->num < first->num))
547 if (!first_opposite && child->num == -1)
548 first_opposite = child;
549 if (child->num == -1)
554 if (current->
num < child->num && (!next || child->
num < next->
num))
561 next = first_opposite ? first_opposite : first;
572 Con *prev = NULL, *first_opposite = NULL, *last = NULL;
575 if (current->
num == -1) {
577 prev =
TAILQ_PREV(current, nodes_head, nodes);
578 if (prev && prev->
num != -1)
581 bool found_current =
false;
587 if (child->type != CT_WORKSPACE)
591 if (!first_opposite || (child->num != -1 && child->num > first_opposite->num))
592 first_opposite = child;
593 if (child == current) {
594 found_current =
true;
595 }
else if (child->num == -1 && found_current) {
609 if (child->type != CT_WORKSPACE)
611 if (!last || (child->num != -1 && last->num < child->num))
613 if (!first_opposite && child->num == -1)
614 first_opposite = child;
615 if (child->num == -1)
620 if (current->
num > child->num && (!prev || child->
num > prev->
num))
627 prev = first_opposite ? first_opposite : last;
641 if (current->
num == -1) {
647 if (child->type != CT_WORKSPACE)
649 if (child->num == -1)
654 if (current->
num < child->num && (!next || child->
num < next->
num))
661 bool found_current =
false;
663 if (child->type != CT_WORKSPACE)
665 if (child == current) {
666 found_current =
true;
667 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
669 goto workspace_next_on_output_end;
677 if (child->type != CT_WORKSPACE)
679 if (!next || (child->num != -1 && child->num < next->
num))
683 workspace_next_on_output_end:
695 DLOG(
"output = %s\n", output->
name);
697 if (current->
num == -1) {
699 prev =
TAILQ_PREV(current, nodes_head, nodes);
700 if (prev && prev->
num != -1)
705 if (child->type != CT_WORKSPACE || child->num == -1)
710 if (current->
num > child->num && (!prev || child->
num > prev->
num))
717 bool found_current =
false;
719 if (child->type != CT_WORKSPACE)
721 if (child == current) {
722 found_current =
true;
723 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
725 goto workspace_prev_on_output_end;
733 if (child->type != CT_WORKSPACE)
735 if (!prev || child->
num > prev->
num)
740 workspace_prev_on_output_end:
750 DLOG(
"No previous workspace name set. Not switching.\n");
763 DLOG(
"No previous workspace name set.\n");
779 TAILQ_FOREACH(child, &(con->floating_head), floating_windows)
792 bool old_flag = ws->
urgent;
794 DLOG(
"Workspace urgency flag changed from %d to %d\n", old_flag, ws->
urgent);
796 if (old_flag != ws->
urgent)
816 DLOG(
"Moving cons\n");
828 DLOG(
"Attaching new split (%p) to ws (%p)\n", split, ws);
849 DLOG(
"Attaching a window to workspace %p / %s\n", ws, ws->
name);
852 DLOG(
"Default layout, just attaching it to the workspace itself.\n");
856 DLOG(
"Non-default layout, creating a new split container\n");
865 DLOG(
"Attaching new split %p to workspace %p\n",
new, ws);
882 ELOG(
"Workspace %p / %s has no children to encapsulate\n", ws, ws->
name);
890 DLOG(
"Moving children of workspace %p / %s into container %p\n",
910 LOG(
"Trying to move workspace %p / %s to output \"%s\".\n", ws, ws->
name, name);
913 if (current_output == NULL) {
914 ELOG(
"Cannot get current output. This is a bug in i3.\n");
920 ELOG(
"Could not get output from string \"%s\"\n", name);
925 LOG(
"got output %p with content %p\n", output, content);
928 LOG(
"Previously visible workspace = %p / %s\n", previously_visible_ws, previously_visible_ws->
name);
932 LOG(
"Creating a new workspace to replace \"%s\" (last on its output).\n", ws->
name);
935 bool used_assignment =
false;
938 if (assignment->
output == NULL || strcmp(assignment->
output, current_output->
name) != 0)
942 Con *workspace = NULL, *out;
945 !strcasecmp(child->name, assignment->
name));
946 if (workspace != NULL)
950 LOG(
"Creating workspace from assignment %s.\n", assignment->
name);
952 used_assignment =
true;
958 if (!used_assignment)
969 if (workspace_was_visible) {
973 LOG(
"workspace was visible, focusing %p / %s now\n", focus_ws, focus_ws->
name);
980 TAILQ_FOREACH(floating_con, &(ws->floating_head), floating_windows)
984 if (workspace_was_visible) {
995 if (ws != previously_visible_ws)
1001 CALL(previously_visible_ws, on_remove_child);
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
struct ws_assignments_head ws_assignments
#define TAILQ_EMPTY(head)
Con * workspace_prev_on_output(void)
Returns the previous workspace on the same output.
#define TAILQ_PREV(elm, headname, field)
int con_num_children(Con *con)
Returns the number of children of this container.
void floating_fix_coordinates(Con *con, Rect *old_rect, Rect *new_rect)
Fixes the coordinates of the floating window whenever the window gets reassigned to a different outpu...
void workspace_show(Con *workspace)
Switches to the given workspace.
static void _workspace_show(Con *workspace)
static void workspace_reassign_sticky(Con *con)
struct bindings_head * bindings
struct ev_loop * main_loop
Con * workspace_attach_to(Con *ws)
Called when a new con (with a window, not an empty or split con) should be attached to the workspace ...
void con_set_urgency(Con *con, bool urgent)
Set urgency flag to the container, all the parent containers and the workspace.
static void _workspace_apply_default_orientation(Con *ws)
long ws_name_to_number(const char *name)
Parses the workspace name as a number.
void ewmh_update_number_of_desktops(void)
Updates _NET_NUMBER_OF_DESKTOPS which we interpret as the number of noninternal workspaces.
void ewmh_update_wm_desktop(void)
Updates _NET_WM_DESKTOP for all windows.
void workspace_show_by_name(const char *num)
Looks up the workspace by name and switches to it.
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
static bool get_urgency_flag(Con *con)
yajl_gen ipc_marshal_workspace_event(const char *change, Con *current, Con *old)
Generates a json workspace event.
Con * workspace_next(void)
Returns the next workspace.
bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_parent, bool force_set_focus)
Closes the given container including all children.
Output * get_output_from_string(Output *current_output, const char *output_str)
Returns an 'output' corresponding to one of left/right/down/up or a specific output name...
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on...
static char ** binding_workspace_names
Con * workspace_prev(void)
Returns the previous workspace.
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
char * parse_string(const char **walk, bool as_word)
Parses a string (or word, if as_word is true).
char * command
Command, like in command mode.
bool workspace_move_to_output(Con *ws, const char *name)
Move the given workspace to the specified output.
void con_focus(Con *con)
Sets input focus to the given container.
void extract_workspace_names_from_bindings(void)
Extracts workspace names from keybindings (e.g.
#define NODES_FOREACH(head)
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
void output_push_sticky_windows(Con *to_focus)
Iterates over all outputs and pushes sticky windows to the currently visible workspace on that output...
#define TAILQ_NEXT(elm, field)
A 'Con' represents everything from the X11 root window down to a single X11 window.
void ewmh_update_desktop_names(void)
Updates _NET_DESKTOP_NAMES: "The names of all virtual desktops.
void ewmh_update_current_desktop(void)
Updates _NET_CURRENT_DESKTOP with the current desktop number.
Output * get_output_for_con(Con *con)
Returns the output for the given con.
void ipc_send_window_event(const char *property, Con *con)
For the window events we send, along the usual "change" field, also the window container, in "container".
void ewmh_update_desktop_viewport(void)
Updates _NET_DESKTOP_VIEWPORT, which is an array of pairs of cardinals that define the top left corne...
static char * previous_workspace_name
Con * con_new(Con *parent, i3Window *window)
Con * workspace_encapsulate(Con *ws)
Creates a new container and re-parents all of children from the given workspace into it...
char * name
Name of the output.
void workspace_back_and_forth(void)
Focuses the previously focused workspace.
void ipc_send_event(const char *event, uint32_t message_type, const char *payload)
Sends the specified event to all IPC clients which are currently connected and subscribed to this kin...
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
Con * workspace_back_and_forth_get(void)
Returns the previously focused workspace con, or NULL if unavailable.
#define TAILQ_FOREACH(var, head, field)
void con_update_parents_urgency(Con *con)
Make all parent containers urgent if con is urgent or clear the urgent flag of all parent containers ...
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
fullscreen_mode_t fullscreen_mode
void con_detach(Con *con)
Detaches the given container from its current parent.
#define GREP_FIRST(dest, head, condition)
#define NODES_FOREACH_REVERSE(head)
void ws_force_orientation(Con *ws, orientation_t orientation)
'Forces' workspace orientation by moving all cons into a new split-con with the same orientation as t...
Con * output_get_content(Con *output)
Returns the output container below the given output container.
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
An Output is a physical output on your graphics driver.
Con * con
Pointer to the Con which represents this output.
float workspace_urgency_timer
By default, urgency is cleared immediately when switching to another workspace leads to focusing the ...
void workspace_update_urgent_flag(Con *ws)
Goes through all clients on the given workspace and updates the workspace’s urgent flag accordingly...
Con * workspace_next_on_output(void)
Returns the next workspace on the same output.
struct ev_timer * urgency_timer
void x_move_win(Con *src, Con *dest)
Moves a child window from Container src to Container dest.
int default_orientation
Default orientation for new containers.
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
layout_t workspace_layout
#define TAILQ_FIRST(head)
Con * _get_sticky(Con *con, const char *sticky_group, Con *exclude)
Con * workspace_get(const char *num, bool *created)
Returns a pointer to the workspace with the given number (starting at 0), creating the workspace if n...
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
Stores which workspace (by name or number) goes to which output.
void ipc_send_workspace_event(const char *change, Con *current, Con *old)
For the workspace events we send, along with the usual "change" field, also the workspace container i...
void x_reparent_child(Con *con, Con *old)
Reparents the child window of the given container (necessary for sticky containers).
Con * create_workspace_on_output(Output *output, Con *content)
Returns a pointer to a new workspace in the given output.
#define CALL(obj, member,...)
void x_set_name(Con *con, const char *name)
Sets the WM_NAME property (so, no UTF8, but used only for debugging anyways) of the given name...
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
static void workspace_defer_update_urgent_hint_cb(EV_P_ ev_timer *w, int revents)
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
Holds a keybinding, consisting of a keycode combined with modifiers and the command which is executed...