*Syntax*:
-------------------------------------------------------
resize grow|shrink <direction> [<px> px [or <ppt> ppt]]
-resize set <width> [px] <height> [px]
+resize set <width> [px | ppt] <height> [px | ppt]
-------------------------------------------------------
Direction can either be one of +up+, +down+, +left+ or +right+. Or you can be
*Examples*:
---------------------------------------
# Read 1 character and mark the current window with this character
-bindsym $mod+m exec i3-input -p 'mark ' -l 1 -P 'Mark: '
+bindsym $mod+m exec i3-input -F 'mark %s' -l 1 -P 'Mark: '
# Read 1 character and go to the window with the character
-bindsym $mod+g exec i3-input -p 'goto ' -l 1 -P 'Goto: '
+bindsym $mod+g exec i3-input -F '[con_mark="%s"] focus' -l 1 -P 'Goto: '
---------------------------------------
Alternatively, if you do not want to mess with +i3-input+, you could create
# The font above is very space-efficient, that is, it looks good, sharp and
# clear in small sizes. However, its unicode glyph coverage is limited, the old
# X core fonts rendering does not support right-to-left and this being a bitmap
-# font, it doesn’t scale on retina/hidpi displays.
+# font, it doesn't scale on retina/hidpi displays.
# use these keys for focus, movement, and resize directions when reaching for
# the arrows is not convenient
# back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
+ bindsym Mod1+r mode "default"
}
bindsym Mod1+r mode "resize"
# back to normal: Enter or Escape
bindcode 36 mode "default"
bindcode 9 mode "default"
+ bindcode $mod+27 mode "default"
}
bindcode $mod+27 mode "resize"
#error "SYSCONFDIR not defined"
#endif
-#define FREE(pointer) \
- do { \
- if (pointer != NULL) { \
- free(pointer); \
- pointer = NULL; \
- } \
+#define FREE(pointer) \
+ do { \
+ free(pointer); \
+ pointer = NULL; \
} while (0)
#include "xcb.h"
static i3Font font;
static i3Font bold_font;
static int char_width;
-static char *socket_path;
+static char *socket_path = NULL;
static xcb_window_t win;
static surface_t surface;
static xcb_key_symbols_t *symbols;
int main(int argc, char *argv[]) {
char *xdg_config_home;
- socket_path = getenv("I3SOCK");
char *pattern = "pango:monospace 8";
char *patternbold = "pango:monospace bold 8";
int o, option_index = 0;
&xkb_base_error) != 1)
errx(EXIT_FAILURE, "Could not setup XKB extension.");
- if (socket_path == NULL)
- socket_path = root_atom_contents("I3_SOCKET_PATH", conn, screen);
-
- if (socket_path == NULL)
- socket_path = "/tmp/i3-ipc.sock";
-
keysyms = xcb_key_symbols_alloc(conn);
xcb_get_modifier_mapping_cookie_t modmap_cookie;
modmap_cookie = xcb_get_modifier_mapping(conn);
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
+#include <signal.h>
#include "libi3.h"
#include "shmlog.h"
static i3_shmlog_header *header;
static char *logbuffer,
*walk;
+static int ipcfd = -1;
+
+static volatile bool interrupted = false;
+
+static void sighandler(int signal) {
+ interrupted = true;
+}
+
+static void disable_shmlog(void) {
+ const char *disablecmd = "debuglog off; shmlog off";
+ if (ipc_send_message(ipcfd, strlen(disablecmd),
+ I3_IPC_MESSAGE_TYPE_COMMAND, (uint8_t *)disablecmd) != 0)
+ err(EXIT_FAILURE, "IPC send");
+
+ /* Ensure the command was sent by waiting for the reply: */
+ uint32_t reply_length = 0;
+ uint8_t *reply = NULL;
+ if (ipc_recv_message(ipcfd, I3_IPC_REPLY_TYPE_COMMAND,
+ &reply_length, &reply) != 0) {
+ err(EXIT_FAILURE, "IPC recv");
+ }
+ free(reply);
+}
static int check_for_wrap(void) {
if (wrap_count == header->wrap_count)
walk += len;
}
+void errorlog(char *fmt, ...) {
+ va_list args;
+
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ va_end(args);
+}
+
int main(int argc, char *argv[]) {
int o, option_index = 0;
bool verbose = false;
exit(1);
}
if (root_atom_contents("I3_CONFIG_PATH", conn, screen) != NULL) {
- fprintf(stderr, "i3-dump-log: ERROR: i3 is running, but SHM logging is not enabled.\n\n");
- if (!is_debug_build()) {
+ fprintf(stderr, "i3-dump-log: ERROR: i3 is running, but SHM logging is not enabled. Enabling SHM log until cancelled\n\n");
+ ipcfd = ipc_connect(NULL);
+ const char *enablecmd = "debuglog on; shmlog 5242880";
+ if (ipc_send_message(ipcfd, strlen(enablecmd),
+ I3_IPC_MESSAGE_TYPE_COMMAND, (uint8_t *)enablecmd) != 0)
+ err(EXIT_FAILURE, "IPC send");
+ /* By the time we receive a reply, I3_SHMLOG_PATH is set: */
+ uint32_t reply_length = 0;
+ uint8_t *reply = NULL;
+ if (ipc_recv_message(ipcfd, I3_IPC_REPLY_TYPE_COMMAND,
+ &reply_length, &reply) != 0) {
+ err(EXIT_FAILURE, "IPC recv");
+ }
+ free(reply);
+
+ atexit(disable_shmlog);
+
+ /* Retry: */
+ shmname = root_atom_contents("I3_SHMLOG_PATH", NULL, 0);
+ if (shmname == NULL && !is_debug_build()) {
fprintf(stderr, "You seem to be using a release version of i3:\n %s\n\n", I3_VERSION);
fprintf(stderr, "Release versions do not use SHM logging by default,\ntherefore i3-dump-log does not work.\n\n");
fprintf(stderr, "Please follow this guide instead:\nhttps://i3wm.org/docs/debugging-release-version.html\n");
exit(1);
}
}
- errx(EXIT_FAILURE, "Cannot get I3_SHMLOG_PATH atom contents. Is i3 running on this display?");
+ if (shmname == NULL) {
+ errx(EXIT_FAILURE, "Cannot get I3_SHMLOG_PATH atom contents. Is i3 running on this display?");
+ }
}
if (*shmname == '\0')
print_till_end();
#if !defined(__OpenBSD__)
- if (follow) {
- /* Since pthread_cond_wait() expects a mutex, we need to provide one.
+ if (!follow) {
+ return 0;
+ }
+
+ /* Handle SIGINT gracefully to invoke atexit handlers, if any. */
+ struct sigaction action;
+ action.sa_handler = sighandler;
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+ sigaction(SIGINT, &action, NULL);
+
+ /* Since pthread_cond_wait() expects a mutex, we need to provide one.
* To not lock i3 (that’s bad, mhkay?) we just define one outside of
* the shared memory. */
- pthread_mutex_t dummy_mutex = PTHREAD_MUTEX_INITIALIZER;
- pthread_mutex_lock(&dummy_mutex);
- while (1) {
- pthread_cond_wait(&(header->condvar), &dummy_mutex);
- /* If this was not a spurious wakeup, print the new lines. */
- if (header->offset_next_write != offset_next_write) {
- offset_next_write = header->offset_next_write;
- print_till_end();
- }
+ pthread_mutex_t dummy_mutex = PTHREAD_MUTEX_INITIALIZER;
+ pthread_mutex_lock(&dummy_mutex);
+ while (!interrupted) {
+ pthread_cond_wait(&(header->condvar), &dummy_mutex);
+ /* If this was not a spurious wakeup, print the new lines. */
+ if (header->offset_next_write != offset_next_write) {
+ offset_next_write = header->offset_next_write;
+ print_till_end();
}
}
-#endif
+#endif
+ exit(0);
return 0;
}
#include <err.h>
#define die(...) errx(EXIT_FAILURE, __VA_ARGS__);
-#define FREE(pointer) \
- do { \
- if (pointer != NULL) { \
- free(pointer); \
- pointer = NULL; \
- } \
+#define FREE(pointer) \
+ do { \
+ free(pointer); \
+ pointer = NULL; \
} while (0)
extern xcb_window_t root;
* the command will be sent to i3 */
static char *format;
-static char *socket_path;
static int sockfd;
static xcb_key_symbols_t *symbols;
static bool modeswitch_active = false;
int main(int argc, char *argv[]) {
format = sstrdup("%s");
- socket_path = getenv("I3SOCK");
+ char *socket_path = NULL;
char *pattern = sstrdup("pango:monospace 8");
int o, option_index = 0;
if (!conn || xcb_connection_has_error(conn))
die("Cannot open display\n");
- if (socket_path == NULL)
- socket_path = root_atom_contents("I3_SOCKET_PATH", conn, screen);
-
- if (socket_path == NULL)
- socket_path = "/tmp/i3-ipc.sock";
-
sockfd = ipc_connect(socket_path);
root_screen = xcb_aux_get_screen(conn, screen);
#include <i3/ipc.h>
-static char *socket_path;
-
/*
* Having verboselog() and errorlog() is necessary when using libi3.
*
if (pledge("stdio rpath unix", NULL) == -1)
err(EXIT_FAILURE, "pledge");
#endif
- char *env_socket_path = getenv("I3SOCK");
- if (env_socket_path)
- socket_path = sstrdup(env_socket_path);
- else
- socket_path = NULL;
+ char *socket_path = NULL;
int o, option_index = 0;
uint32_t message_type = I3_IPC_MESSAGE_TYPE_RUN_COMMAND;
char *payload = NULL;
while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
if (o == 's') {
- if (socket_path != NULL)
- free(socket_path);
+ free(socket_path);
socket_path = sstrdup(optarg);
} else if (o == 't') {
if (strcasecmp(optarg, "command") == 0) {
}
}
- if (socket_path == NULL)
- socket_path = root_atom_contents("I3_SOCKET_PATH", NULL, 0);
-
- /* Fall back to the default socket path */
- if (socket_path == NULL)
- socket_path = sstrdup("/tmp/i3-ipc.sock");
-
/* Use all arguments, separated by whitespace, as payload.
* This way, you don’t have to do i3-msg 'mark foo', you can use
* i3-msg mark foo */
if (!payload)
payload = sstrdup("");
- int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
- if (sockfd == -1)
- err(EXIT_FAILURE, "Could not create socket");
-
- struct sockaddr_un addr;
- memset(&addr, 0, sizeof(struct sockaddr_un));
- addr.sun_family = AF_LOCAL;
- strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
- if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0)
- err(EXIT_FAILURE, "Could not connect to i3 on socket \"%s\"", socket_path);
-
+ int sockfd = ipc_connect(socket_path);
if (ipc_send_message(sockfd, strlen(payload), message_type, (uint8_t *)payload) == -1)
err(EXIT_FAILURE, "IPC: write()");
free(payload);
#include <err.h>
#define die(...) errx(EXIT_FAILURE, __VA_ARGS__);
-#define FREE(pointer) \
- do { \
- if (pointer != NULL) { \
- free(pointer); \
- pointer = NULL; \
- } \
+#define FREE(pointer) \
+ do { \
+ free(pointer); \
+ pointer = NULL; \
} while (0)
#define xmacro(atom) xcb_atom_t A_##atom;
# We welcome patches that add distribution-specific mechanisms to find the
# preferred terminal emulator. On Debian, there is the x-terminal-emulator
# symlink for example.
-for terminal in "$TERMINAL" x-terminal-emulator urxvt rxvt termit terminator Eterm aterm uxterm xterm gnome-terminal roxterm xfce4-terminal termite lxterminal mate-terminal terminology st qterminal lilyterm tilix terminix konsole; do
+for terminal in "$TERMINAL" x-terminal-emulator urxvt rxvt termit terminator Eterm aterm uxterm xterm gnome-terminal roxterm xfce4-terminal termite lxterminal mate-terminal terminology st qterminal lilyterm tilix terminix konsole kitty; do
if command -v "$terminal" > /dev/null 2>&1; then
exec "$terminal" "$@"
fi
#define STARTS_WITH(string, len, needle) (((len) >= strlen((needle))) && strncasecmp((string), (needle), strlen((needle))) == 0)
/* Securely free p */
-#define FREE(p) \
- do { \
- if (p != NULL) { \
- free(p); \
- p = NULL; \
- } \
+#define FREE(p) \
+ do { \
+ free(p); \
+ p = NULL; \
} while (0)
/* Securely free single-linked list */
if (!strcmp(cur_key, "mode")) {
DLOG("mode = %.*s, len = %d\n", len, val, len);
- config.hide_on_modifier = (len == 4 && !strncmp((const char *)val, "dock", strlen("dock")) ? M_DOCK
- : (len == 4 && !strncmp((const char *)val, "hide", strlen("hide")) ? M_HIDE
- : M_INVISIBLE));
+ config.hide_on_modifier = (len == strlen("dock") && !strncmp((const char *)val, "dock", strlen("dock")) ? M_DOCK
+ : (len == strlen("hide") && !strncmp((const char *)val, "hide", strlen("hide")) ? M_HIDE
+ : M_INVISIBLE));
return 1;
}
if (!strcmp(cur_key, "hidden_state")) {
DLOG("hidden_state = %.*s, len = %d\n", len, val, len);
- config.hidden_state = (len == 4 && !strncmp((const char *)val, "hide", strlen("hide")) ? S_HIDE : S_SHOW);
+ config.hidden_state = (len == strlen("hide") && !strncmp((const char *)val, "hide", strlen("hide")) ? S_HIDE : S_SHOW);
return 1;
}
if (!strcmp(cur_key, "modifier")) {
DLOG("modifier = %.*s\n", len, val);
- if (len == 4 && !strncmp((const char *)val, "none", strlen("none"))) {
+ if (len == strlen("none") && !strncmp((const char *)val, "none", strlen("none"))) {
config.modifier = XCB_NONE;
return 1;
}
- if (len == 5 && !strncmp((const char *)val, "shift", strlen("shift"))) {
+ if (len == strlen("shift") && !strncmp((const char *)val, "shift", strlen("shift"))) {
config.modifier = ShiftMask;
return 1;
}
- if (len == 4 && !strncmp((const char *)val, "ctrl", strlen("ctrl"))) {
+ if (len == strlen("ctrl") && !strncmp((const char *)val, "ctrl", strlen("ctrl"))) {
config.modifier = ControlMask;
return 1;
}
- if (len == 4 && !strncmp((const char *)val, "Mod", strlen("Mod"))) {
+ if (len == strlen("Mod") + 1 && !strncmp((const char *)val, "Mod", strlen("Mod"))) {
switch (val[3]) {
case '1':
config.modifier = Mod1Mask;
if (!strcmp(cur_key, "position")) {
DLOG("position = %.*s\n", len, val);
- config.position = (len == 3 && !strncmp((const char *)val, "top", strlen("top")) ? POS_TOP : POS_BOT);
+ config.position = (len == strlen("top") && !strncmp((const char *)val, "top", strlen("top")) ? POS_TOP : POS_BOT);
return 1;
}
/* Event watchers, to interact with the user */
ev_prepare *xcb_prep;
-ev_check *xcb_chk;
ev_io *xcb_io;
ev_io *xkb_io;
}
/*
- * This function is called immediately before the main loop locks. We flush xcb
- * then (and only then)
+ * This function is called immediately before the main loop locks. We check for
+ * events from X11, handle them, then flush our outgoing queue.
*
*/
void xcb_prep_cb(struct ev_loop *loop, ev_prepare *watcher, int revents) {
- xcb_flush(xcb_connection);
-}
-
-/*
- * This function is called immediately after the main loop locks, so when one
- * of the watchers registered an event.
- * We check whether an X-Event arrived and handle it.
- *
- */
-void xcb_chk_cb(struct ev_loop *loop, ev_check *watcher, int revents) {
xcb_generic_event_t *event;
if (xcb_connection_has_error(xcb_connection)) {
}
free(event);
}
+
+ xcb_flush(xcb_connection);
}
/*
/* The various watchers to communicate with xcb */
xcb_io = smalloc(sizeof(ev_io));
xcb_prep = smalloc(sizeof(ev_prepare));
- xcb_chk = smalloc(sizeof(ev_check));
ev_io_init(xcb_io, &xcb_io_cb, xcb_get_file_descriptor(xcb_connection), EV_READ);
ev_prepare_init(xcb_prep, &xcb_prep_cb);
- ev_check_init(xcb_chk, &xcb_chk_cb);
-
- /* Within an event loop iteration, run the xcb_chk watcher last: other
- * watchers might call xcb_flush(), which, unexpectedly, can also read
- * events into the queue (see _xcb_conn_wait). Hence, we need to drain xcb’s
- * queue last, otherwise we risk dead-locking. */
- ev_set_priority(xcb_chk, EV_MINPRI);
ev_io_start(main_loop, xcb_io);
ev_prepare_start(main_loop, xcb_prep);
- ev_check_start(main_loop, xcb_chk);
/* Now we get the atoms and save them in a nice data structure */
get_atoms();
xcb_aux_sync(xcb_connection);
xcb_disconnect(xcb_connection);
- ev_check_stop(main_loop, xcb_chk);
ev_prepare_stop(main_loop, xcb_prep);
ev_io_stop(main_loop, xcb_io);
- FREE(xcb_chk);
FREE(xcb_prep);
FREE(xcb_io);
}
* Implementation of 'resize set <px> [px] <px> [px]'.
*
*/
-void cmd_resize_set(I3_CMD, long cwidth, long cheight);
+void cmd_resize_set(I3_CMD, long cwidth, const char *mode_width, long cheight, const char *mode_height);
/**
* Implementation of 'resize grow|shrink <direction> [<px> px] [or <ppt> ppt]'.
extern xcb_window_t root;
extern struct ev_loop *main_loop;
extern bool only_check_config;
+extern bool force_xinerama;
break; \
}
-#define FREE(pointer) \
- do { \
- if (pointer != NULL) { \
- free(pointer); \
- pointer = NULL; \
- } \
+#define FREE(pointer) \
+ do { \
+ free(pointer); \
+ pointer = NULL; \
} while (0)
#define CALL(obj, member, ...) obj->member(obj, ##__VA_ARGS__)
*
*/
int ipc_connect(const char *socket_path) {
+ char *path = NULL;
+ if (socket_path != NULL) {
+ path = sstrdup(socket_path);
+ }
+
+ if (path == NULL) {
+ if ((path = getenv("I3SOCK")) != NULL) {
+ path = sstrdup(path);
+ }
+ }
+
+ if (path == NULL) {
+ path = root_atom_contents("I3_SOCKET_PATH", NULL, 0);
+ }
+
+ if (path == NULL) {
+ path = sstrdup("/tmp/i3-ipc.sock");
+ }
+
int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (sockfd == -1)
err(EXIT_FAILURE, "Could not create socket");
struct sockaddr_un addr;
memset(&addr, 0, sizeof(struct sockaddr_un));
addr.sun_family = AF_LOCAL;
- strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
+ strncpy(addr.sun_path, path, sizeof(addr.sun_path) - 1);
if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0)
- err(EXIT_FAILURE, "Could not connect to i3");
-
+ err(EXIT_FAILURE, "Could not connect to i3 on socket %s", path);
+ free(path);
return sockfd;
}
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
+#include <inttypes.h>
#include <i3/ipc.h>
if (n == -1)
return -1;
if (n == 0) {
- return -2;
+ if (read_bytes == 0) {
+ return -2;
+ } else {
+ ELOG("IPC: unexpected EOF while reading header, got %" PRIu32 " bytes, want %" PRIu32 " bytes\n",
+ read_bytes, to_read);
+ return -3;
+ }
}
read_bytes += n;
}
if (memcmp(walk, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC)) != 0) {
- ELOG("IPC: invalid magic in reply\n");
+ ELOG("IPC: invalid magic in header, got \"%.*s\", want \"%s\"\n",
+ (int)strlen(I3_IPC_MAGIC), walk, I3_IPC_MAGIC);
return -3;
}
*reply = smalloc(*reply_length);
read_bytes = 0;
- int n;
while (read_bytes < *reply_length) {
- if ((n = read(sockfd, *reply + read_bytes, *reply_length - read_bytes)) == -1) {
+ const int n = read(sockfd, *reply + read_bytes, *reply_length - read_bytes);
+ if (n == -1) {
if (errno == EINTR || errno == EAGAIN)
continue;
return -1;
}
+ if (n == 0) {
+ ELOG("IPC: unexpected EOF while reading payload, got %" PRIu32 " bytes, want %" PRIu32 " bytes\n",
+ read_bytes, *reply_length);
+ return -3;
+ }
read_bytes += n;
}
* tilix
* terminix
* konsole
+* kitty
Please don’t complain about the order: If the user has any preference, they will
have $TERMINAL set or modified their i3 configuration file.
-> RESIZE_WIDTH
state RESIZE_WIDTH:
- 'px'
+ mode_width = 'px', 'ppt'
->
height = number
-> RESIZE_HEIGHT
state RESIZE_HEIGHT:
- 'px', end
- -> call cmd_resize_set(&width, &height)
+ mode_height = 'px', 'ppt'
+ ->
+ end
+ -> call cmd_resize_set(&width, $mode_width, &height, $mode_height)
# rename workspace <name> to <name>
# rename workspace to <name>
}
/*
- * Implementation of 'resize set <px> [px] <px> [px]'.
+ * Implementation of 'resize set <width> [px | ppt] <height> [px | ppt]'.
*
*/
-void cmd_resize_set(I3_CMD, long cwidth, long cheight) {
- DLOG("resizing to %ldx%ld px\n", cwidth, cheight);
+void cmd_resize_set(I3_CMD, long cwidth, const char *mode_width, long cheight, const char *mode_height) {
+ DLOG("resizing to %ld %s x %ld %s\n", cwidth, mode_width, cheight, mode_height);
if (cwidth <= 0 || cheight <= 0) {
- ELOG("Resize failed: dimensions cannot be negative (was %ldx%ld)\n", cwidth, cheight);
+ ELOG("Resize failed: dimensions cannot be negative (was %ld %s x %ld %s)\n", cwidth, mode_width, cheight, mode_height);
return;
}
TAILQ_FOREACH(current, &owindows, owindows) {
Con *floating_con;
if ((floating_con = con_inside_floating(current->con))) {
+ Con *output = con_get_output(floating_con);
+ if (mode_width && strcmp(mode_width, "ppt") == 0) {
+ cwidth = output->rect.width * ((double)cwidth / 100.0);
+ }
+ if (mode_height && strcmp(mode_height, "ppt") == 0) {
+ cheight = output->rect.height * ((double)cheight / 100.0);
+ }
floating_resize(floating_con, cwidth, cheight);
} else {
ELOG("Resize failed: %p not a floating container\n", current->con);
owindow *current;
TAILQ_FOREACH(current, &owindows, owindows) {
Con *ws = con_get_workspace(current->con);
+ if (con_is_internal(ws)) {
+ continue;
+ }
+
bool success = workspace_move_to_output(ws, name);
if (!success) {
ELOG("Failed to move workspace to output.\n");
*
*/
void display_running_version(void) {
- char *socket_path = root_atom_contents("I3_SOCKET_PATH", conn, conn_screen);
- if (socket_path == NULL)
- exit(EXIT_SUCCESS);
-
char *pid_from_atom = root_atom_contents("I3_PID", conn, conn_screen);
if (pid_from_atom == NULL) {
/* If I3_PID is not set, the running version is older than 4.2-200. */
printf("(Getting version from running i3, press ctrl-c to abort…)");
fflush(stdout);
- /* TODO: refactor this with the code for sending commands */
- int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
- if (sockfd == -1)
- err(EXIT_FAILURE, "Could not create socket");
-
- struct sockaddr_un addr;
- memset(&addr, 0, sizeof(struct sockaddr_un));
- addr.sun_family = AF_LOCAL;
- strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
- if (connect(sockfd, (const struct sockaddr *)&addr, sizeof(struct sockaddr_un)) < 0)
- err(EXIT_FAILURE, "Could not connect to i3");
-
+ int sockfd = ipc_connect(NULL);
if (ipc_send_message(sockfd, 0, I3_IPC_MESSAGE_TYPE_GET_VERSION,
(uint8_t *)"") == -1)
err(EXIT_FAILURE, "IPC: write()");
yajl_free(handle);
free(reply);
free(pid_from_atom);
- free(socket_path);
}
/* Custom data structure used to track dragging-related events. */
struct drag_x11_cb {
- ev_check check;
+ ev_prepare prepare;
/* Whether this modal event loop should be exited and with which result. */
drag_result_t result;
const void *extra;
};
-static void xcb_drag_check_cb(EV_P_ ev_check *w, int revents) {
+static void xcb_drag_prepare_cb(EV_P_ ev_prepare *w, int revents) {
struct drag_x11_cb *dragloop = (struct drag_x11_cb *)w->data;
xcb_motion_notify_event_t *last_motion_notify = NULL;
xcb_generic_event_t *event;
dragloop->extra);
}
free(last_motion_notify);
+
+ xcb_flush(conn);
}
/*
.callback = callback,
.extra = extra,
};
- ev_check *check = &loop.check;
+ ev_prepare *prepare = &loop.prepare;
if (con)
loop.old_rect = con->rect;
- ev_check_init(check, xcb_drag_check_cb);
- check->data = &loop;
+ ev_prepare_init(prepare, xcb_drag_prepare_cb);
+ prepare->data = &loop;
main_set_x11_cb(false);
- ev_check_start(main_loop, check);
+ ev_prepare_start(main_loop, prepare);
while (loop.result == DRAGGING)
ev_run(main_loop, EVRUN_ONCE);
- ev_check_stop(main_loop, check);
+ ev_prepare_stop(main_loop, prepare);
main_set_x11_cb(true);
xcb_ungrab_keyboard(conn, XCB_CURRENT_TIME);
scratchpad_show(con);
} else {
workspace_show(ws);
+ /* Re-set focus, even if unchanged from i3’s perspective. */
+ focused_id = XCB_NONE;
con_focus(con);
}
} else {
}
DLOG("ConfigureNotify for root window 0x%08x\n", event->event);
+ if (force_xinerama) {
+ return;
+ }
randr_query_outputs();
}
/** The number of file descriptors passed via socket activation. */
int listen_fds;
-/* We keep the xcb_check watcher around to be able to enable and disable it
+/* We keep the xcb_prepare watcher around to be able to enable and disable it
* temporarily for drag_pointer(). */
-static struct ev_check *xcb_check;
+static struct ev_prepare *xcb_prepare;
extern Con *focused;
bool xcursor_supported = true;
bool xkb_supported = true;
+bool force_xinerama = false;
+
/*
- * This callback is only a dummy, see xcb_prepare_cb and xcb_check_cb.
+ * This callback is only a dummy, see xcb_prepare_cb.
* See also man libev(3): "ev_prepare" and "ev_check" - customise your event loop
*
*/
static void xcb_got_event(EV_P_ struct ev_io *w, int revents) {
- /* empty, because xcb_prepare_cb and xcb_check_cb are used */
+ /* empty, because xcb_prepare_cb are used */
}
/*
- * Flush before blocking (and waiting for new events)
+ * Called just before the event loop sleeps. Ensures xcb’s incoming and outgoing
+ * queues are empty so that any activity will trigger another event loop
+ * iteration, and hence another xcb_prepare_cb invocation.
*
*/
static void xcb_prepare_cb(EV_P_ ev_prepare *w, int revents) {
- xcb_flush(conn);
-}
-
-/*
- * Instead of polling the X connection socket we leave this to
- * xcb_poll_for_event() which knows better than we can ever know.
- *
- */
-static void xcb_check_cb(EV_P_ ev_check *w, int revents) {
+ /* Process all queued (and possibly new) events before the event loop
+ sleeps. */
xcb_generic_event_t *event;
while ((event = xcb_poll_for_event(conn)) != NULL) {
free(event);
}
+
+ /* Flush all queued events to X11. */
+ xcb_flush(conn);
}
/*
void main_set_x11_cb(bool enable) {
DLOG("Setting main X11 callback to enabled=%d\n", enable);
if (enable) {
- ev_check_start(main_loop, xcb_check);
+ ev_prepare_start(main_loop, xcb_prepare);
/* Trigger the watcher explicitly to handle all remaining X11 events.
* drag_pointer()’s event handler exits in the middle of the loop. */
- ev_feed_event(main_loop, xcb_check, 0);
+ ev_feed_event(main_loop, xcb_prepare, 0);
} else {
- ev_check_stop(main_loop, xcb_check);
+ ev_prepare_stop(main_loop, xcb_prepare);
}
}
fflush(stderr);
shm_unlink(shmlogname);
}
+ ipc_shutdown(SHUTDOWN_REASON_EXIT);
+ unlink(config.ipc_socket_path);
}
/*
- * (One-shot) Handler for all signals with default action "Term", see signal(7)
+ * (One-shot) Handler for all signals with default action "Core", see signal(7)
*
* Unlinks the SHM log and re-raises the signal.
*
*/
-static void handle_signal(int sig, siginfo_t *info, void *data) {
+static void handle_core_signal(int sig, siginfo_t *info, void *data) {
if (*shmlogname != '\0') {
shm_unlink(shmlogname);
}
raise(sig);
}
+/*
+ * (One-shot) Handler for all signals with default action "Term", see signal(7)
+ *
+ * Exits the program gracefully.
+ *
+ */
+static void handle_term_signal(struct ev_loop *loop, ev_signal *signal, int revents) {
+ /* We exit gracefully here in the sense that cleanup handlers
+ * installed via atexit are invoked. */
+ exit(128 + signal->signum);
+}
+
+/*
+ * Set up handlers for all signals with default action "Term", see signal(7)
+ *
+ */
+static void setup_term_handlers(void) {
+ static struct ev_signal signal_watchers[6];
+ size_t num_watchers = sizeof(signal_watchers) / sizeof(signal_watchers[0]);
+
+ /* We have to rely on libev functionality here and should not use
+ * sigaction handlers because we need to invoke the exit handlers
+ * and cannot do so from an asynchronous signal handling context as
+ * not all code triggered during exit is signal safe (and exiting
+ * the main loop from said handler is not easily possible). libev's
+ * signal handlers does not impose such a constraint on us. */
+ ev_signal_init(&signal_watchers[0], handle_term_signal, SIGHUP);
+ ev_signal_init(&signal_watchers[1], handle_term_signal, SIGINT);
+ ev_signal_init(&signal_watchers[2], handle_term_signal, SIGALRM);
+ ev_signal_init(&signal_watchers[3], handle_term_signal, SIGTERM);
+ ev_signal_init(&signal_watchers[4], handle_term_signal, SIGUSR1);
+ ev_signal_init(&signal_watchers[5], handle_term_signal, SIGUSR1);
+ for (size_t i = 0; i < num_watchers; i++) {
+ ev_signal_start(main_loop, &signal_watchers[i]);
+ /* The signal handlers should not block ev_run from returning
+ * and so none of the signal handlers should hold a reference to
+ * the main loop. */
+ ev_unref(main_loop);
+ }
+}
+
int main(int argc, char *argv[]) {
/* Keep a symbol pointing to the I3_VERSION string constant so that we have
* it in gdb backtraces. */
bool autostart = true;
char *layout_path = NULL;
bool delete_layout_path = false;
- bool force_xinerama = false;
bool disable_randr15 = false;
char *fake_outputs = NULL;
bool disable_signalhandler = false;
config.ipc_socket_path = sstrdup(config.ipc_socket_path);
}
+ if (config.force_xinerama) {
+ force_xinerama = true;
+ }
+
xcb_void_cookie_t cookie;
cookie = xcb_change_window_attributes_checked(conn, root, XCB_CW_EVENT_MASK, (uint32_t[]){ROOT_EVENT_MASK});
xcb_generic_error_t *error = xcb_request_check(conn, cookie);
fake_outputs_init(fake_outputs);
FREE(fake_outputs);
config.fake_outputs = NULL;
- } else if (force_xinerama || config.force_xinerama) {
+ } else if (force_xinerama) {
/* Force Xinerama (for drivers which don't support RandR yet, esp. the
* nVidia binary graphics driver), when specified either in the config
* file or on command-line */
ewmh_update_desktop_viewport();
struct ev_io *xcb_watcher = scalloc(1, sizeof(struct ev_io));
- xcb_check = scalloc(1, sizeof(struct ev_check));
- struct ev_prepare *xcb_prepare = scalloc(1, sizeof(struct ev_prepare));
+ xcb_prepare = scalloc(1, sizeof(struct ev_prepare));
ev_io_init(xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ);
ev_io_start(main_loop, xcb_watcher);
- ev_check_init(xcb_check, xcb_check_cb);
- ev_check_start(main_loop, xcb_check);
-
ev_prepare_init(xcb_prepare, xcb_prepare_cb);
ev_prepare_start(main_loop, xcb_prepare);
err(EXIT_FAILURE, "pledge");
#endif
- struct sigaction action;
-
- action.sa_sigaction = handle_signal;
- action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
- sigemptyset(&action.sa_mask);
-
if (!disable_signalhandler)
setup_signal_handler();
else {
+ struct sigaction action;
+
+ action.sa_sigaction = handle_core_signal;
+ action.sa_flags = SA_NODEFER | SA_RESETHAND | SA_SIGINFO;
+ sigemptyset(&action.sa_mask);
+
/* Catch all signals with default action "Core", see signal(7) */
if (sigaction(SIGQUIT, &action, NULL) == -1 ||
sigaction(SIGILL, &action, NULL) == -1 ||
ELOG("Could not setup signal handler.\n");
}
- /* Catch all signals with default action "Term", see signal(7) */
- if (sigaction(SIGHUP, &action, NULL) == -1 ||
- sigaction(SIGINT, &action, NULL) == -1 ||
- sigaction(SIGALRM, &action, NULL) == -1 ||
- sigaction(SIGUSR1, &action, NULL) == -1 ||
- sigaction(SIGUSR2, &action, NULL) == -1)
- ELOG("Could not setup signal handler.\n");
-
+ setup_term_handlers();
/* Ignore SIGPIPE to survive errors when an IPC client disconnects
* while we are sending them a message */
signal(SIGPIPE, SIG_IGN);
free(command);
}
- /* Make sure to destroy the event loop to invoke the cleeanup callbacks
+ /* Make sure to destroy the event loop to invoke the cleanup callbacks
* when calling exit() */
atexit(i3_exit);
static xcb_connection_t *restore_conn;
static struct ev_io *xcb_watcher;
-static struct ev_check *xcb_check;
static struct ev_prepare *xcb_prepare;
static void restore_handle_event(int type, xcb_generic_event_t *event);
}
static void restore_xcb_prepare_cb(EV_P_ ev_prepare *w, int revents) {
- xcb_flush(restore_conn);
-}
-
-static void restore_xcb_check_cb(EV_P_ ev_check *w, int revents) {
xcb_generic_event_t *event;
if (xcb_connection_has_error(restore_conn)) {
free(event);
}
+
+ xcb_flush(restore_conn);
}
/*
/* This is not the initial connect, but a reconnect, most likely
* because our X11 connection was killed (e.g. by a user with xkill. */
ev_io_stop(main_loop, xcb_watcher);
- ev_check_stop(main_loop, xcb_check);
ev_prepare_stop(main_loop, xcb_prepare);
placeholder_state *state;
*/
xcb_disconnect(restore_conn);
free(xcb_watcher);
- free(xcb_check);
free(xcb_prepare);
}
}
xcb_watcher = scalloc(1, sizeof(struct ev_io));
- xcb_check = scalloc(1, sizeof(struct ev_check));
xcb_prepare = scalloc(1, sizeof(struct ev_prepare));
ev_io_init(xcb_watcher, restore_xcb_got_event, xcb_get_file_descriptor(restore_conn), EV_READ);
ev_io_start(main_loop, xcb_watcher);
- ev_check_init(xcb_check, restore_xcb_check_cb);
- ev_check_start(main_loop, xcb_check);
-
ev_prepare_init(xcb_prepare, restore_xcb_prepare_cb);
ev_prepare_start(main_loop, xcb_prepare);
}
if (!workspace)
return false;
- workspace_show(workspace);
-
- /* If a workspace has an active fullscreen container, one of its
- * children should always be focused. The above workspace_show()
- * should be adequate for that, so return. */
- if (con_get_fullscreen_con(workspace, CF_OUTPUT))
- return true;
-
- Con *focus = con_descend_direction(workspace, direction);
-
- /* special case: if there was no tiling con to focus and the workspace
- * has a floating con in the focus stack, focus the top of the focus
- * stack (which may be floating) */
- if (focus == workspace)
+ Con *focus = con_descend_tiling_focused(workspace);
+ if (focus == workspace) {
focus = con_descend_focused(workspace);
+ }
if (focus) {
con_focus(focus);
*
*/
void update_shmlog_atom() {
- xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
- A_I3_SHMLOG_PATH, A_UTF8_STRING, 8,
- strlen(shmlogname), shmlogname);
+ if (*shmlogname == '\0') {
+ xcb_delete_property(conn, root, A_I3_SHMLOG_PATH);
+ } else {
+ xcb_change_property(conn, XCB_PROP_MODE_REPLACE, root,
+ A_I3_SHMLOG_PATH, A_UTF8_STRING, 8,
+ strlen(shmlogname), shmlogname);
+ }
}
/*
use List::Util qw(first);
use Time::HiRes qw(sleep);
use Cwd qw(abs_path);
+use POSIX ':sys_wait_h';
use Scalar::Util qw(blessed);
use SocketActivation;
use i3test::Util qw(slurp);
cmd
sync_with_i3
exit_gracefully
+ exit_forcefully
workspace_exists
focused_ws
get_socket_path
} else {
kill(-9, $i3_pid)
- or $tester->BAIL_OUT("could not kill i3");
+ or $tester->BAIL_OUT("could not kill i3: $!");
waitpid $i3_pid, 0;
}
my ($class, %args) = @_;
my $pkg = caller;
+ $x ||= i3test::X11->new;
+ # set the pointer to a predictable position in case a previous test has
+ # disturbed it
+ $x->warp_pointer(
+ 0, # src_window (None)
+ $x->get_root_window(), # dst_window (None)
+ 0, # src_x
+ 0, # src_y
+ 0, # src_width
+ 0, # src_height
+ 0, # dst_x
+ 0); # dst_y
+ # Synchronize with X11 to ensure the pointer has been warped before i3
+ # starts up.
+ $x->get_input_focus_reply($x->get_input_focus()->{sequence});
+
$i3_autostart = delete($args{i3_autostart}) // 1;
my $i3_config = delete($args{i3_config}) // '-default';
strict->import;
warnings->import;
- $x ||= i3test::X11->new;
- # set the pointer to a predictable position in case a previous test has
- # disturbed it
- $x->root->warp_pointer(0, 0);
$cv->recv if $i3_autostart;
@_ = ($class);
sub wait_for_event {
my ($timeout, $cb) = @_;
- my $cv = AE::cv;
-
$x->flush;
- # unfortunately, there is no constant for this
- my $ae_read = 0;
-
- my $guard = AE::io $x->get_file_descriptor, $ae_read, sub {
- while (defined(my $event = $x->poll_for_event)) {
- if ($cb->($event)) {
- $cv->send(1);
- last;
- }
- }
- };
-
- # Trigger timeout after $timeout seconds (can be fractional)
- my $t = AE::timer $timeout, 0, sub { warn "timeout ($timeout secs)"; $cv->send(0) };
-
- my $result = $cv->recv;
- undef $t;
- undef $guard;
- return $result;
+ while (defined(my $event = $x->wait_for_event)) {
+ return 1 if $cb->($event);
+ }
}
=head2 wait_for_map($window)
$window->map;
wait_for_map($window);
+
+ # MapWindow is sent before i3 even starts rendering: the window is placed at
+ # temporary off-screen coordinates first, and x_push_changes() sends further
+ # X11 requests to set focus etc. Hence, we sync with i3 before continuing.
+ sync_with_i3();
+
return $window;
}
$_sync_window = open_window(
rect => [ -15, -15, 10, 10 ],
override_redirect => 1,
+ dont_map => 1,
);
}
if (!$exited) {
kill(9, $pid)
- or $tester->BAIL_OUT("could not kill i3");
+ or $tester->BAIL_OUT("could not kill i3: $!");
}
if ($socketpath =~ m,^/tmp/i3-test-socket-,) {
undef $i3_pid;
}
+=head2 exit_forcefully($pid, [ $signal ])
+
+Tries to exit i3 forcefully by sending a signal (defaults to SIGTERM).
+
+You only need to use this function if you want to test signal handling
+(in which case you must have launched i3 on your own with
+C<launch_with_config>).
+
+ use i3test i3_autostart => 0;
+ my $pid = launch_with_config($config);
+ # …
+ exit_forcefully($pid);
+
+=cut
+sub exit_forcefully {
+ my ($pid, $signal) = @_;
+ $signal ||= 'TERM';
+
+ # Send the given signal to the i3 instance and wait for up to 10s
+ # for it to terminate.
+ kill($signal, $pid)
+ or $tester->BAIL_OUT("could not kill i3: $!");
+ my $status;
+ my $timeout = 10;
+ do {
+ $status = waitpid $pid, WNOHANG;
+
+ if ($status <= 0) {
+ sleep(1);
+ $timeout--;
+ }
+ } while ($status <= 0 && $timeout > 0);
+
+ if ($status <= 0) {
+ kill('KILL', $pid)
+ or $tester->BAIL_OUT("could not kill i3: $!");
+ waitpid $pid, 0;
+ }
+ undef $i3_pid;
+}
+
=head2 get_socket_path([ $cache ])
Gets the socket path from the C<I3_SOCKET_PATH> atom stored on the X11 root
# 3: change size of the shared memory log buffer and verify old content is gone
################################################################################
-cmd 'shmlog ' . (23 * 1024 * 1024);
+cmd 'shmlog ' . (1 * 1024 * 1024);
run [ 'i3-dump-log' ],
'>', \$stdout,
is($events[0]->{container}->{name}, $name, "$name focused");
}
-subtest 'focus left (1)', \&focus_subtest, 'focus left', 'Window 1';
-subtest 'focus left (2)', \&focus_subtest, 'focus left', 'Window 0';
-subtest 'focus right (1)', \&focus_subtest, 'focus right', 'Window 1';
-subtest 'focus right (2)', \&focus_subtest, 'focus right', 'Window 2';
-subtest 'focus right (3)', \&focus_subtest, 'focus right', 'Window 0';
-subtest 'focus left', \&focus_subtest, 'focus left', 'Window 2';
+subtest 'focus left (1)', \&focus_subtest, 'focus left', $win1->name;
+subtest 'focus left (2)', \&focus_subtest, 'focus left', $win0->name;
+subtest 'focus right (1)', \&focus_subtest, 'focus right', $win1->name;
+subtest 'focus right (2)', \&focus_subtest, 'focus right', $win2->name;
+subtest 'focus right (3)', \&focus_subtest, 'focus right', $win0->name;
+subtest 'focus left', \&focus_subtest, 'focus left', $win2->name;
done_testing;
# Test behavior of "resize <width> <height>" command.
# Ticket: #1727
# Bug still in: 4.10.2-1-gc0dbc5d
-use i3test;
+use i3test i3_config => <<EOT;
+# i3 config file (v4)
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
+
+fake-outputs 1333x999+0+0
+workspace ws output fake-0
+EOT
################################################################################
# Check that setting floating windows size works
cmp_ok($content[0]->{rect}->{width}, '==', 100, 'width changed to 100 px');
cmp_ok($content[0]->{rect}->{height}, '==', 250, 'height changed to 250 px');
+################################################################################
+# Same but with ppt instead of px
+################################################################################
+
+kill_all_windows;
+$tmp = 'ws';
+cmd "workspace $tmp";
+open_floating_window;
+
+@content = @{get_ws($tmp)->{floating_nodes}};
+is(@content, 1, 'one floating node on this ws');
+
+$oldrect = $content[0]->{rect};
+
+cmd 'resize set 33 ppt 20 ppt';
+my $expected_width = int(0.33 * 1333);
+my $expected_height = int(0.2 * 999);
+
+@content = @{get_ws($tmp)->{floating_nodes}};
+cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
+cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y untouched');
+cmp_ok($content[0]->{rect}->{width}, '!=', $oldrect->{width}, 'width changed');
+cmp_ok($content[0]->{rect}->{height}, '!=', $oldrect->{width}, 'height changed');
+cmp_ok($content[0]->{rect}->{width}, '==', $expected_width, "width changed to $expected_width px");
+cmp_ok($content[0]->{rect}->{height}, '==', $expected_height, "height changed to $expected_height px");
+
+################################################################################
+# Mix ppt and px in a single resize set command
+################################################################################
+
+cmd 'resize set 44 ppt 111 px';
+my $expected_width = int(0.44 * 1333);
+my $expected_height = 111;
+
+@content = @{get_ws($tmp)->{floating_nodes}};
+cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
+cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y untouched');
+cmp_ok($content[0]->{rect}->{width}, '==', $expected_width, "width changed to $expected_width px");
+cmp_ok($content[0]->{rect}->{height}, '==', $expected_height, "height changed to $expected_height px");
+
+cmd 'resize set 222 px 100 ppt';
+my $expected_width = 222;
+my $expected_height = 999;
+
+@content = @{get_ws($tmp)->{floating_nodes}};
+cmp_ok($content[0]->{rect}->{x}, '==', $oldrect->{x}, 'x untouched');
+cmp_ok($content[0]->{rect}->{y}, '==', $oldrect->{y}, 'y untouched');
+cmp_ok($content[0]->{rect}->{width}, '==', $expected_width, "width changed to $expected_width px");
+cmp_ok($content[0]->{rect}->{height}, '==', $expected_height, "height changed to $expected_height px");
+
done_testing;
($x0, $x1) = workspaces_per_screen();
ok($ws1 ~~ @$x0, 'ws1 on fake-0');
+################################################################################
+# Verify that '[class=".*"] move workspace to output' doesn't fail when
+# containers in the scratchpad are matched.
+# See issue: #3064.
+################################################################################
+my $__i3_scratch = get_ws('__i3_scratch');
+is(scalar @{$__i3_scratch->{floating_nodes}}, 0, 'scratchpad is empty');
+
+my $ws0 = fresh_workspace(output => 0);
+open_window(wm_class => 'a');
+
+my $ws1 = fresh_workspace(output => 1);
+open_window(wm_class => 'b');
+my $scratchpad_window = open_window(wm_class => 'c');
+cmd 'move to scratchpad';
+
+($x0, $x1) = workspaces_per_screen();
+ok($ws0 ~~ @$x0, 'ws0 on fake-0');
+ok($ws1 ~~ @$x1, 'ws1 on fake-1');
+
+my $reply = cmd '[class=".*"] move workspace to output fake-1';
+ok($reply->[0]->{success}, 'move successful');
+
+($x0, $x1) = workspaces_per_screen();
+ok($ws0 ~~ @$x1, 'ws0 on fake-1');
+ok($ws1 ~~ @$x1, 'ws1 on fake-1');
+
+$__i3_scratch = get_ws('__i3_scratch');
+is(scalar @{$__i3_scratch->{floating_nodes}}, 1, 'window still in scratchpad');
+
################################################################################
done_testing;
cmd "workspace $s2_ws";
cmd 'focus right';
-is($x->input_focus, $sixth->id, 'sixth window focused');
+is($x->input_focus, $seventh->id, 'seventh window focused');
reset_focus $s3_ws;
cmd "workspace $s2_ws";
cmd 'focus parent';
cmd 'focus parent';
cmd 'split v';
+# Focus second or else $first gets to the top of the focus stack.
+cmd '[id=' . $second->id . '] focus';
reset_focus $s0_ws;
cmd "workspace $s3_ws";
cmd 'focus up';
is($x->input_focus, $second->id, 'second window focused');
+###################################################################
+# Test that focus (left|down|right|up), when focusing across
+# outputs, doesn't focus the next window in the given direction but
+# the most focused window of the container in the given direction.
+# In the following layout:
+# [ WS1*[ ] WS2[ H[ A B* ] ] ]
+# (where the asterisk denotes the focused container within its
+# parent) moving right from WS1 should focus B which is focused
+# inside WS2, not A which is the next window on the right of WS1.
+# See issue #1160.
+###################################################################
+
+kill_all_windows;
+
+sync_with_i3;
+$x->root->warp_pointer(1025, 0); # Second screen.
+sync_with_i3;
+$s1_ws = fresh_workspace;
+$first = open_window;
+$second = open_window;
+
+sync_with_i3;
+$x->root->warp_pointer(0, 0); # First screen.
+sync_with_i3;
+$s0_ws = fresh_workspace;
+open_window;
+$third = open_window;
+
+cmd 'focus right';
+is($x->input_focus, $second->id, 'second window (rightmost) focused');
+cmd 'focus left';
+is($x->input_focus, $first->id, 'first window focused');
+cmd 'focus left';
+is($x->input_focus, $third->id, 'third window focused');
+
+
+###################################################################
+# Similar but with a tabbed layout.
+###################################################################
+
+cmd 'layout tabbed';
+$fourth = open_window;
+cmd 'focus left';
+is($x->input_focus, $third->id, 'third window (tabbed) focused');
+cmd "workspace $s1_ws";
+cmd 'focus left';
+is($x->input_focus, $third->id, 'third window (tabbed) focused');
+
+
+###################################################################
+# Similar but with a stacked layout on the bottom screen.
+###################################################################
+
+sync_with_i3;
+$x->root->warp_pointer(0, 769); # Third screen.
+sync_with_i3;
+$s2_ws = fresh_workspace;
+cmd 'layout stacked';
+$fifth = open_window;
+$sixth = open_window;
+
+cmd "workspace $s0_ws";
+cmd 'focus down';
+is($x->input_focus, $sixth->id, 'sixth window (stacked) focused');
+
+###################################################################
+# Similar but with a more complex layout.
+###################################################################
+
+sync_with_i3;
+$x->root->warp_pointer(1025, 769); # Fourth screen.
+sync_with_i3;
+$s3_ws = fresh_workspace;
+open_window;
+open_window;
+cmd 'split v';
+open_window;
+open_window;
+cmd 'split h';
+my $nested = open_window;
+open_window;
+cmd 'focus left';
+is($x->input_focus, $nested->id, 'nested window focused');
+
+cmd "workspace $s1_ws";
+cmd 'focus down';
+is($x->input_focus, $nested->id, 'nested window focused from workspace above');
+
+cmd "workspace $s2_ws";
+cmd 'focus right';
+is($x->input_focus, $nested->id, 'nested window focused from workspace on the left');
+
done_testing;
my $left = open_window;
my $right = open_window;
sync_with_i3;
-my $con = $cv->recv;
-is($con->{window}, $right->{id}, 'focus is initially on the right container');
sub focus_subtest {
my ($subscribecb, $want, $msg) = @_;
--- /dev/null
+#!perl
+# vim:ts=4:sw=4:expandtab
+#
+# Please read the following documents before working on tests:
+# • https://build.i3wm.org/docs/testsuite.html
+# (or docs/testsuite)
+#
+# • https://build.i3wm.org/docs/lib-i3test.html
+# (alternatively: perldoc ./testcases/lib/i3test.pm)
+#
+# • https://build.i3wm.org/docs/ipc.html
+# (or docs/ipc)
+#
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
+# (unless you are already familiar with Perl)
+#
+# Tests that the socket file is cleaned up properly after gracefully
+# shutting down i3 via SIGTERM.
+# Ticket: #3049
+use i3test i3_autostart => 0;
+
+my $config = <<EOT;
+# i3 config file (v4)
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
+EOT
+
+my $pid = launch_with_config($config, dont_add_socket_path => 1);
+my $socket = get_socket_path();
+ok(-S $socket, "socket $socket exists");
+
+exit_forcefully($pid, 'TERM');
+
+ok(!-e $socket, "socket $socket no longer exists");
+
+done_testing;