28 Con *output, *workspace = NULL;
42 Con *output, *workspace = NULL;
63 DLOG(
"Auto orientation. Workspace size set to (%d,%d), setting layout to %d.\n",
85 if (name && strcmp(assignment->
name, name) == 0) {
86 DLOG(
"Found workspace name assignment to output \"%s\"\n", assignment->
output);
88 if (assigned_by_name) {
90 return assigned_by_name->
con;
94 name_is_digits(assignment->
name) &&
96 DLOG(
"Found workspace number assignment to output \"%s\"\n", assignment->
output);
98 if (assigned_by_num) {
99 output = assigned_by_num->
con;
113 return assigned && assigned == output->
con;
125 if (workspace == NULL) {
126 LOG(
"Creating new workspace \"%s\"\n", num);
140 LOG(
"got output %p with content %p\n", output, content);
143 workspace =
con_new(NULL, NULL);
145 sasprintf(&name,
"[i3 con] workspace %s", num);
148 workspace->
type = CT_WORKSPACE;
152 workspace->
num = parsed_num;
153 LOG(
"num = %d\n", workspace->
num);
155 workspace->
parent = content;
167 }
else if (created != NULL) {
192 if (strlen(bind->
command) < strlen(
"workspace ") ||
193 strncasecmp(bind->
command,
"workspace", strlen(
"workspace")) != 0)
196 const char *target = bind->
command + strlen(
"workspace ");
197 while (*target ==
' ' || *target ==
'\t')
204 if (strncasecmp(target,
"next", strlen(
"next")) == 0 ||
205 strncasecmp(target,
"prev", strlen(
"prev")) == 0 ||
206 strncasecmp(target,
"next_on_output", strlen(
"next_on_output")) == 0 ||
207 strncasecmp(target,
"prev_on_output", strlen(
"prev_on_output")) == 0 ||
208 strncasecmp(target,
"number", strlen(
"number")) == 0 ||
209 strncasecmp(target,
"back_and_forth", strlen(
"back_and_forth")) == 0 ||
210 strncasecmp(target,
"current", strlen(
"current")) == 0)
213 if (target_name == NULL)
215 if (strncasecmp(target_name,
"__", strlen(
"__")) == 0) {
216 LOG(
"Cannot create workspace \"%s\". Names starting with __ are i3-internal.\n", target);
220 DLOG(
"Saving workspace name \"%s\"\n", target_name);
240 ws->
type = CT_WORKSPACE;
249 if (assigned && assigned != output->
con) {
259 LOG(
"Used number %d for workspace with name %s\n", ws->
num, ws->
name);
267 DLOG(
"Getting next unused workspace by number\n");
273 DLOG(
"result for ws %d: exists = %d\n", c, exists);
303 LOG(
"workspace visible? fs = %p, ws = %p\n", fs, ws);
315 if (current != exclude &&
317 current->
window != NULL &&
327 if (current != exclude &&
329 current->
window != NULL &&
359 LOG(
"Ah, this one is sticky: %s / %p\n", current->
name, current);
365 LOG(
"No window found for this sticky group\n");
378 LOG(
"re-assigned window from src %p to dest %p\n", src, current);
398 DLOG(
"Resetting urgency flag of con %p by timer\n", con);
412 Con *current, *old = NULL;
430 if (workspace == current) {
431 DLOG(
"Not switching, already there.\n");
456 DLOG(
"switching to %p / %s\n", workspace, workspace->
name);
476 DLOG(
"Deferring reset of urgency flag of con %p on newly shown workspace %p\n",
485 DLOG(
"Resetting urgency timer of con %p on workspace %p\n",
494 DLOG(
"old = %p / %s\n", old, (old ? old->
name :
"(null)"));
503 LOG(
"Closing old workspace (%p / %s), it is empty\n", old, old->
name);
507 const unsigned char *payload;
509 y(get_buf, &payload, &length);
510 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE, (
const char *)payload);
515 if (old == old_focus) {
531 if (old_output != new_output) {
558 Con *next = NULL, *first = NULL, *first_opposite = NULL;
561 if (current->
num == -1) {
563 if ((next =
TAILQ_NEXT(current, nodes)) != NULL)
565 bool found_current =
false;
571 if (child->type != CT_WORKSPACE)
575 if (!first_opposite || (child->num != -1 && child->num < first_opposite->num))
576 first_opposite = child;
577 if (child == current) {
578 found_current =
true;
579 }
else if (child->num == -1 && found_current) {
592 if (child->type != CT_WORKSPACE)
594 if (!first || (child->num != -1 && child->num < first->num))
596 if (!first_opposite && child->num == -1)
597 first_opposite = child;
598 if (child->num == -1)
603 if (current->
num < child->num && (!next || child->
num < next->
num))
610 next = first_opposite ? first_opposite : first;
621 Con *prev = NULL, *first_opposite = NULL, *last = NULL;
624 if (current->
num == -1) {
626 prev =
TAILQ_PREV(current, nodes_head, nodes);
627 if (prev && prev->
num != -1)
630 bool found_current =
false;
636 if (child->type != CT_WORKSPACE)
640 if (!first_opposite || (child->num != -1 && child->num > first_opposite->num))
641 first_opposite = child;
642 if (child == current) {
643 found_current =
true;
644 }
else if (child->num == -1 && found_current) {
658 if (child->type != CT_WORKSPACE)
660 if (!last || (child->num != -1 && last->num < child->num))
662 if (!first_opposite && child->num == -1)
663 first_opposite = child;
664 if (child->num == -1)
669 if (current->
num > child->num && (!prev || child->
num > prev->
num))
676 prev = first_opposite ? first_opposite : last;
690 if (current->
num == -1) {
696 if (child->type != CT_WORKSPACE)
698 if (child->num == -1)
703 if (current->
num < child->num && (!next || child->
num < next->
num))
710 bool found_current =
false;
712 if (child->type != CT_WORKSPACE)
714 if (child == current) {
715 found_current =
true;
716 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
718 goto workspace_next_on_output_end;
726 if (child->type != CT_WORKSPACE)
728 if (!next || (child->num != -1 && child->num < next->
num))
732 workspace_next_on_output_end:
744 DLOG(
"output = %s\n", output->
name);
746 if (current->
num == -1) {
748 prev =
TAILQ_PREV(current, nodes_head, nodes);
749 if (prev && prev->
num != -1)
754 if (child->type != CT_WORKSPACE || child->num == -1)
759 if (current->
num > child->num && (!prev || child->
num > prev->
num))
766 bool found_current =
false;
768 if (child->type != CT_WORKSPACE)
770 if (child == current) {
771 found_current =
true;
772 }
else if (child->num == -1 && (current->
num != -1 || found_current)) {
774 goto workspace_prev_on_output_end;
782 if (child->type != CT_WORKSPACE)
784 if (!prev || child->
num > prev->
num)
789 workspace_prev_on_output_end:
799 DLOG(
"No previous workspace name set. Not switching.\n");
812 DLOG(
"No previous workspace name set.\n");
841 bool old_flag = ws->
urgent;
843 DLOG(
"Workspace urgency flag changed from %d to %d\n", old_flag, ws->
urgent);
845 if (old_flag != ws->
urgent)
865 DLOG(
"Moving cons\n");
880 DLOG(
"Attaching new split (%p) to ws (%p)\n", split, ws);
898 DLOG(
"Attaching a window to workspace %p / %s\n", ws, ws->
name);
901 DLOG(
"Default layout, just attaching it to the workspace itself.\n");
905 DLOG(
"Non-default layout, creating a new split container\n");
914 DLOG(
"Attaching new split %p to workspace %p\n",
new, ws);
931 ELOG(
"Workspace %p / %s has no children to encapsulate\n", ws, ws->
name);
941 DLOG(
"Moving children of workspace %p / %s into container %p\n",
966 if (current_output == NULL) {
967 ELOG(
"Cannot get current output. This is a bug in i3.\n");
972 LOG(
"got output %p with content %p\n", output, content);
975 LOG(
"Previously visible workspace = %p / %s\n", previously_visible_ws, previously_visible_ws->
name);
979 LOG(
"Creating a new workspace to replace \"%s\" (last on its output).\n", ws->
name);
982 bool used_assignment =
false;
994 LOG(
"Creating workspace from assignment %s.\n", assignment->
name);
996 used_assignment =
true;
1002 if (!used_assignment)
1008 DLOG(
"Detaching\n");
1013 if (workspace_was_visible) {
1017 LOG(
"workspace was visible, focusing %p / %s now\n", focus_ws, focus_ws->
name);
1028 if (workspace_was_visible) {
1039 if (ws != previously_visible_ws)
1045 CALL(previously_visible_ws, on_remove_child);
void con_fix_percent(Con *con)
Updates the percent attribute of the children of the given container.
void set_focus_order(Con *con, Con **focus_order)
Clear the container's focus stack and re-add it using the provided container array.
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...
void con_detach(Con *con)
Detaches the given container from its current parent.
char * parse_string(const char **walk, bool as_word)
Parses a string (or word, if as_word is true).
#define NODES_FOREACH(head)
void * srealloc(void *ptr, size_t size)
Safe-wrapper around realloc which exits if realloc returns NULL (meaning that there is no more memory...
void workspace_show(Con *workspace)
Switches to the given workspace.
void x_move_win(Con *src, Con *dest)
Moves a child window from Container src to Container dest.
Output * get_output_for_con(Con *con)
Returns the output for the given con.
Stores which workspace (by name or number) goes to which output.
void ewmh_update_wm_desktop(void)
Updates _NET_WM_DESKTOP for all windows.
char * command
Command, like in command mode.
#define TAILQ_EMPTY(head)
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...
Con * workspace_encapsulate(Con *ws)
Creates a new container and re-parents all of children from the given workspace into it...
float workspace_urgency_timer
By default, urgency is cleared immediately when switching to another workspace leads to focusing the ...
void x_set_warp_to(Rect *rect)
Set warp_to coordinates.
static char ** binding_workspace_names
An Output is a physical output on your graphics driver.
Con * workspace_prev(void)
Returns the previous workspace.
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
void con_focus(Con *con)
Sets input focus to the given container.
Holds a keybinding, consisting of a keycode combined with modifiers and the command which is executed...
bool output_triggers_assignment(Output *output, struct Workspace_Assignment *assignment)
Returns true if the first output assigned to a workspace with the given workspace assignment is the s...
Con ** get_focus_order(Con *con)
Iterate over the container's focus stack and return an array with the containers inside it...
struct bindings_head * bindings
void ewmh_update_number_of_desktops(void)
Updates _NET_NUMBER_OF_DESKTOPS which we interpret as the number of noninternal workspaces.
#define NODES_FOREACH_REVERSE(head)
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".
static bool get_urgency_flag(Con *con)
layout_t workspace_layout
#define TAILQ_FOREACH_REVERSE(var, head, headname, field)
void x_reparent_child(Con *con, Con *old)
Reparents the child window of the given container (necessary for sticky containers).
void ewmh_update_current_desktop(void)
Updates _NET_CURRENT_DESKTOP with the current desktop number.
Output * get_output_by_name(const char *name, const bool require_active)
Returns the output with the given name or NULL.
#define CALL(obj, member,...)
static Con * get_assigned_output(const char *name, long parsed_num)
void ewmh_update_desktop_viewport(void)
Updates _NET_DESKTOP_VIEWPORT, which is an array of pairs of cardinals that define the top left corne...
Con * workspace_next(void)
Returns the next workspace.
#define TAILQ_FIRST(head)
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...
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...
static void _workspace_apply_default_orientation(Con *ws)
void workspace_show_by_name(const char *num)
Looks up the workspace by name and switches to it.
static Con * _get_sticky(Con *con, const char *sticky_group, Con *exclude)
Con * con
Pointer to the Con which represents this output.
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...
int con_num_children(Con *con)
Returns the number of children of this container.
long ws_name_to_number(const char *name)
Parses the workspace name as a number.
void workspace_update_urgent_flag(Con *ws)
Goes through all clients on the given workspace and updates the workspace’s urgent flag accordingly...
#define TAILQ_NEXT(elm, field)
void tree_render(void)
Renders the tree, that is rendering all outputs using render_con() and pushing the changes to X11 usi...
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 * workspace_back_and_forth_get(void)
Returns the previously focused workspace con, or NULL if unavailable.
void ewmh_update_desktop_names(void)
Updates _NET_DESKTOP_NAMES: "The names of all virtual desktops.
void con_set_urgency(Con *con, bool urgent)
Set urgency flag to the container, all the parent containers and the workspace.
void workspace_back_and_forth(void)
Focuses the previously focused workspace.
static void workspace_reassign_sticky(Con *con)
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
int default_orientation
Default orientation for new containers.
void output_push_sticky_windows(Con *old_focus)
Iterates over all outputs and pushes sticky windows to the currently visible workspace on that output...
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
Con * output_get_content(Con *output)
Returns the output container below the given output container.
struct ev_timer * urgency_timer
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...
void extract_workspace_names_from_bindings(void)
Extracts workspace names from keybindings (e.g.
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
Con * get_existing_workspace_by_name(const char *name)
Returns the workspace with the given name or NULL if such a workspace does not exist.
static void workspace_defer_update_urgent_hint_cb(EV_P_ ev_timer *w, int revents)
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_parent)
Closes the given container including all children.
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...
yajl_gen ipc_marshal_workspace_event(const char *change, Con *current, Con *old)
Generates a json workspace event.
A 'Con' represents everything from the X11 root window down to a single X11 window.
Con * con_new(Con *parent, i3Window *window)
A wrapper for con_new_skeleton, to retain the old con_new behaviour.
#define GREP_FIRST(dest, head, condition)
#define TAILQ_PREV(elm, headname, field)
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
static char * previous_workspace_name
struct ws_assignments_head ws_assignments
Con * create_workspace_on_output(Output *output, Con *content)
Returns a pointer to a new workspace in the given output.
struct ev_loop * main_loop
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
bool workspace_move_to_output(Con *ws, Output *output)
Move the given workspace to the specified output.
Con * workspace_prev_on_output(void)
Returns the previous workspace on the same 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...
Con * workspace_next_on_output(void)
Returns the next workspace on the same output.
char * output_primary_name(Output *output)
Retrieves the primary name of an output.
Con * get_existing_workspace_by_num(int num)
Returns the workspace with the given number or NULL if such a workspace does not exist.
#define TAILQ_FOREACH(var, head, field)
fullscreen_mode_t fullscreen_mode
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 ...
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 ...