mirror of
https://github.com/i3/i3.git
synced 2026-08-18 02:52:38 +00:00
Chore: Code cleanup and style improvements (#6516)
This PR is a pure linting and code cleanup effort with no functional
changes, focusing on improving code quality and consistency.
The bulk of the changes involve:
* Code Formatting: The entire codebase was reformatted after updating
our `clang-format` version.
* Compiler Warnings: Addressed `-Wsuggest-attribute` warnings from GCC
by applying `pure`, `const`, and `format` attributes where appropriate.
This helps the compiler with optimizations and bug detection.
* Code Modernization:
* Variable declarations were moved closer to their first use or into
tighter scopes.
* `memset` calls were replaced with C99 zero-initializers (`= {0}`).
* Redundant `struct` keywords, unnecessary type casts, and some
superfluous `return` statements were removed.
* CI Adjustments: The GitHub Actions workflow was updated to correctly
apply compiler flags for both GCC and Clang.
This commit is contained in:
7
.github/workflows/main.yml
vendored
7
.github/workflows/main.yml
vendored
@ -37,7 +37,12 @@ jobs:
|
||||
docker pull ${{ env.BASENAME_UBUNTU }} || ./travis/docker-build-and-push.sh ${{ env.BASENAME_UBUNTU }} travis/travis-base-ubuntu.Dockerfile
|
||||
- name: build i3
|
||||
run: |
|
||||
docker run -v $PWD:/usr/src/i3/ -w /usr/src/i3 -e CC ${{ env.BASENAME }} /bin/sh -c 'rm -rf build; mkdir -p build && cd build && CFLAGS="-Wformat -Wformat-security -Wextra -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Werror -fno-common -D_FORTIFY_SOURCE=3" meson setup .. -Ddocs=true -Dmans=true -Db_sanitize="address,undefined" --buildtype=debugoptimized && ninja -v'
|
||||
CFLAGS="-Wformat -Wformat-security -Wall -Wextra -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Werror -fno-common -D_FORTIFY_SOURCE=3"
|
||||
if [ "${{ matrix.compiler }}" = "gcc" ]; then
|
||||
CFLAGS="$CFLAGS -Wsuggest-attribute=pure -Wsuggest-attribute=const -Wsuggest-attribute=format"
|
||||
fi
|
||||
export CFLAGS
|
||||
docker run -v $PWD:/usr/src/i3/ -w /usr/src/i3 -e CC -e CFLAGS ${{ env.BASENAME }} /bin/sh -c 'rm -rf build; mkdir -p build && cd build && meson setup .. -Ddocs=true -Dmans=true -Db_sanitize="address,undefined" --buildtype=debugoptimized && ninja -v'
|
||||
- name: Upload docs html for manual inspection
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
|
||||
@ -102,7 +102,7 @@ static uint8_t *concat_strings(char **glyphs, int max) {
|
||||
walk += strlen(glyphs[c]);
|
||||
}
|
||||
}
|
||||
printf("output = %s\n", output);
|
||||
printf("output = %s\n", (char *)output);
|
||||
return output;
|
||||
}
|
||||
|
||||
@ -111,7 +111,7 @@ static uint8_t *concat_strings(char **glyphs, int max) {
|
||||
* be called from the code with event == NULL or from X with event != NULL.
|
||||
*
|
||||
*/
|
||||
static int handle_expose(void *data, xcb_connection_t *conn, xcb_expose_event_t *event) {
|
||||
static int handle_expose(xcb_connection_t *conn) {
|
||||
printf("expose!\n");
|
||||
|
||||
color_t border_color = draw_util_hex_to_color("#FF0000");
|
||||
@ -249,7 +249,7 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
|
||||
input_position--;
|
||||
free(glyphs_utf8[input_position]);
|
||||
|
||||
handle_expose(NULL, conn, NULL);
|
||||
handle_expose(conn);
|
||||
return 1;
|
||||
}
|
||||
if (sym == XK_Escape) {
|
||||
@ -295,7 +295,7 @@ static int handle_key_press(void *ignored, xcb_connection_t *conn, xcb_key_press
|
||||
finish_input();
|
||||
}
|
||||
|
||||
handle_expose(NULL, conn, NULL);
|
||||
handle_expose(conn);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -518,11 +518,12 @@ int main(int argc, char *argv[]) {
|
||||
while ((event = xcb_wait_for_event(conn)) != NULL) {
|
||||
if (event->response_type == 0) {
|
||||
fprintf(stderr, "X11 Error received! sequence %x\n", event->sequence);
|
||||
free(event);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Strip off the highest bit (set if the event is generated) */
|
||||
int type = (event->response_type & 0x7F);
|
||||
const int type = (event->response_type & 0x7F);
|
||||
|
||||
switch (type) {
|
||||
case XCB_KEY_PRESS:
|
||||
@ -535,9 +536,10 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
case XCB_EXPOSE:
|
||||
if (((xcb_expose_event_t *)event)->count == 0) {
|
||||
handle_expose(NULL, conn, (xcb_expose_event_t *)event);
|
||||
handle_expose(conn);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@ -242,7 +242,7 @@ static int button_draw(button_t *button, int position) {
|
||||
* be called from the code with event == NULL or from X with event != NULL.
|
||||
*
|
||||
*/
|
||||
static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) {
|
||||
static int handle_expose(xcb_connection_t *conn) {
|
||||
/* draw background */
|
||||
draw_util_clear_surface(&bar, color_background);
|
||||
/* draw message */
|
||||
@ -633,7 +633,7 @@ int main(int argc, char *argv[]) {
|
||||
switch (type) {
|
||||
case XCB_EXPOSE:
|
||||
if (((xcb_expose_event_t *)event)->count == 0) {
|
||||
handle_expose(conn, (xcb_expose_event_t *)event);
|
||||
handle_expose(conn);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
1
i3bar/.gitignore
vendored
1
i3bar/.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
i3bar
|
||||
*.o
|
||||
core
|
||||
doc/i3bar.1
|
||||
|
||||
@ -215,7 +215,7 @@ static int stdin_start_map(void *context) {
|
||||
static int stdin_map_key(void *context, const unsigned char *key, size_t len) {
|
||||
parser_ctx *ctx = context;
|
||||
FREE(ctx->last_map_key);
|
||||
sasprintf(&(ctx->last_map_key), "%.*s", len, key);
|
||||
sasprintf(&(ctx->last_map_key), "%.*s", (int)len, key);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -254,15 +254,15 @@ static int stdin_string(void *context, const unsigned char *val, size_t len) {
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp(ctx->last_map_key, "color") == 0) {
|
||||
sasprintf(&(ctx->block.color), "%.*s", len, val);
|
||||
sasprintf(&(ctx->block.color), "%.*s", (int)len, val);
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp(ctx->last_map_key, "background") == 0) {
|
||||
sasprintf(&(ctx->block.background), "%.*s", len, val);
|
||||
sasprintf(&(ctx->block.background), "%.*s", (int)len, val);
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp(ctx->last_map_key, "border") == 0) {
|
||||
sasprintf(&(ctx->block.border), "%.*s", len, val);
|
||||
sasprintf(&(ctx->block.border), "%.*s", (int)len, val);
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp(ctx->last_map_key, "markup") == 0) {
|
||||
@ -280,15 +280,15 @@ static int stdin_string(void *context, const unsigned char *val, size_t len) {
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp(ctx->last_map_key, "min_width") == 0) {
|
||||
sasprintf(&(ctx->block.min_width_str), "%.*s", len, val);
|
||||
sasprintf(&(ctx->block.min_width_str), "%.*s", (int)len, val);
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp(ctx->last_map_key, "name") == 0) {
|
||||
sasprintf(&(ctx->block.name), "%.*s", len, val);
|
||||
sasprintf(&(ctx->block.name), "%.*s", (int)len, val);
|
||||
return 1;
|
||||
}
|
||||
if (strcasecmp(ctx->last_map_key, "instance") == 0) {
|
||||
sasprintf(&(ctx->block.instance), "%.*s", len, val);
|
||||
sasprintf(&(ctx->block.instance), "%.*s", (int)len, val);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -663,7 +663,7 @@ static void child_sig_cb(struct ev_loop *loop, ev_child *watcher, int revents) {
|
||||
watcher->pid,
|
||||
exit_status);
|
||||
|
||||
void (*error_function_pointer)(const char *, ...) = NULL;
|
||||
__attribute__((format(printf, 1, 2))) void (*error_function_pointer)(const char *, ...) = NULL;
|
||||
const char *command_type = "";
|
||||
i3bar_child *c = NULL;
|
||||
if (watcher->pid == status_child.pid) {
|
||||
|
||||
@ -29,7 +29,7 @@ static bool parsing_padding;
|
||||
*/
|
||||
static int config_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
|
||||
FREE(cur_key);
|
||||
sasprintf(&(cur_key), "%.*s", keyLen, keyVal);
|
||||
sasprintf(&(cur_key), "%.*s", (int)keyLen, keyVal);
|
||||
|
||||
if (strcmp(cur_key, "bindings") == 0) {
|
||||
parsing_bindings = true;
|
||||
|
||||
@ -30,7 +30,7 @@ static int mode_string_cb(void *params_, const unsigned char *val, size_t len) {
|
||||
struct mode_json_params *params = (struct mode_json_params *)params_;
|
||||
|
||||
if (!strcmp(params->cur_key, "change")) {
|
||||
sasprintf(&(params->name), "%.*s", len, val);
|
||||
sasprintf(&(params->name), "%.*s", (int)len, val);
|
||||
FREE(params->cur_key);
|
||||
return 1;
|
||||
}
|
||||
@ -67,7 +67,7 @@ static int mode_boolean_cb(void *params_, int val) {
|
||||
static int mode_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
|
||||
struct mode_json_params *params = (struct mode_json_params *)params_;
|
||||
FREE(params->cur_key);
|
||||
sasprintf(&(params->cur_key), "%.*s", keyLen, keyVal);
|
||||
sasprintf(&(params->cur_key), "%.*s", (int)keyLen, keyVal);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -106,7 +106,7 @@ static int outputs_string_cb(void *params_, const unsigned char *val, size_t len
|
||||
|
||||
if (!strcmp(params->cur_key, "current_workspace")) {
|
||||
char *copy = NULL;
|
||||
sasprintf(©, "%.*s", len, val);
|
||||
sasprintf(©, "%.*s", (int)len, val);
|
||||
|
||||
char *end;
|
||||
errno = 0;
|
||||
@ -125,7 +125,7 @@ static int outputs_string_cb(void *params_, const unsigned char *val, size_t len
|
||||
return 0;
|
||||
}
|
||||
|
||||
sasprintf(&(params->outputs_walk->name), "%.*s", len, val);
|
||||
sasprintf(&(params->outputs_walk->name), "%.*s", (int)len, val);
|
||||
|
||||
FREE(params->cur_key);
|
||||
return 1;
|
||||
@ -235,7 +235,7 @@ static int outputs_end_map_cb(void *params_) {
|
||||
static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) {
|
||||
struct outputs_json_params *params = (struct outputs_json_params *)params_;
|
||||
FREE(params->cur_key);
|
||||
sasprintf(&(params->cur_key), "%.*s", keyLen, keyVal);
|
||||
sasprintf(&(params->cur_key), "%.*s", (int)keyLen, keyVal);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -151,7 +151,7 @@ static int workspaces_string_cb(void *params_, const unsigned char *val, const s
|
||||
if (!strcmp(params->cur_key, "output")) {
|
||||
/* We add the ws to the TAILQ of the output, it belongs to */
|
||||
char *output_name = NULL;
|
||||
sasprintf(&output_name, "%.*s", len, val);
|
||||
sasprintf(&output_name, "%.*s", (int)len, val);
|
||||
|
||||
i3_output *target = get_output_by_name(output_name);
|
||||
i3_ws *ws = params->workspaces_walk;
|
||||
@ -228,7 +228,7 @@ static int workspaces_end_map_cb(void *params_) {
|
||||
static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, const size_t keyLen) {
|
||||
struct workspaces_json_params *params = params_;
|
||||
FREE(params->cur_key);
|
||||
sasprintf(¶ms->cur_key, "%.*s", keyLen, keyVal);
|
||||
sasprintf(¶ms->cur_key, "%.*s", (int)keyLen, keyVal);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -591,7 +591,7 @@ static void focus_workspace(i3_ws *ws) {
|
||||
if (ws->id != 0) {
|
||||
/* Workspace ID has higher precedence since the workspace_command is
|
||||
* allowed to change workspace names as long as it provides a valid ID. */
|
||||
sasprintf(&buffer, "[con_id=%lld] focus workspace", ws->id);
|
||||
sasprintf(&buffer, "[con_id=%lu] focus workspace", ws->id);
|
||||
goto done;
|
||||
}
|
||||
|
||||
@ -912,12 +912,10 @@ static void handle_client_message(xcb_client_message_event_t *event) {
|
||||
DLOG("_NET_SYSTEM_TRAY_OPCODE received\n");
|
||||
/* event->data.data32[0] is the timestamp */
|
||||
uint32_t op = event->data.data32[1];
|
||||
uint32_t mask;
|
||||
uint32_t values[2];
|
||||
if (op == SYSTEM_TRAY_REQUEST_DOCK) {
|
||||
xcb_window_t client = event->data.data32[2];
|
||||
|
||||
mask = XCB_CW_EVENT_MASK;
|
||||
const xcb_window_t client = event->data.data32[2];
|
||||
uint32_t mask = XCB_CW_EVENT_MASK;
|
||||
|
||||
/* Needed to get the most recent value of XEMBED_MAPPED. */
|
||||
values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE;
|
||||
|
||||
@ -28,9 +28,10 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/xcb_icccm.h>
|
||||
#include <xcb/xcb_keysyms.h>
|
||||
#include <xcb/xkb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
|
||||
#include "libi3.h"
|
||||
#include "data.h"
|
||||
|
||||
@ -90,7 +90,7 @@ void cmd_nop(I3_CMD, const char *comment);
|
||||
* Implementation of 'append_layout <path>'.
|
||||
*
|
||||
*/
|
||||
void cmd_append_layout(I3_CMD, const char *path);
|
||||
void cmd_append_layout(I3_CMD, const char *cpath);
|
||||
|
||||
/**
|
||||
* Implementation of 'workspace next|prev|next_on_output|prev_on_output'.
|
||||
@ -102,7 +102,7 @@ void cmd_workspace(I3_CMD, const char *which);
|
||||
* Implementation of 'workspace [--no-auto-back-and-forth] number <number>'
|
||||
*
|
||||
*/
|
||||
void cmd_workspace_number(I3_CMD, const char *which, const char *no_auto_back_and_forth);
|
||||
void cmd_workspace_number(I3_CMD, const char *which, const char *no_auto_back_and_forth_str);
|
||||
|
||||
/**
|
||||
* Implementation of 'workspace back_and_forth'.
|
||||
@ -114,7 +114,7 @@ void cmd_workspace_back_and_forth(I3_CMD);
|
||||
* Implementation of 'workspace [--no-auto-back-and-forth] <name>'
|
||||
*
|
||||
*/
|
||||
void cmd_workspace_name(I3_CMD, const char *name, const char *no_auto_back_and_forth);
|
||||
void cmd_workspace_name(I3_CMD, const char *name, const char *no_auto_back_and_forth_str);
|
||||
|
||||
/**
|
||||
* Implementation of 'mark [--add|--replace] [--toggle] <mark>'
|
||||
@ -174,13 +174,13 @@ void cmd_exec(I3_CMD, const char *nosn, const char *command);
|
||||
* Implementation of 'focus left|right|up|down'.
|
||||
*
|
||||
*/
|
||||
void cmd_focus_direction(I3_CMD, const char *direction);
|
||||
void cmd_focus_direction(I3_CMD, const char *direction_str);
|
||||
|
||||
/**
|
||||
* Implementation of 'focus next|prev sibling'
|
||||
*
|
||||
*/
|
||||
void cmd_focus_sibling(I3_CMD, const char *direction);
|
||||
void cmd_focus_sibling(I3_CMD, const char *direction_str);
|
||||
|
||||
/**
|
||||
* Implementation of 'focus tiling|floating|mode_toggle'.
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
* A utility function to convert a string containing the group and modifiers to
|
||||
* the corresponding bit mask.
|
||||
*/
|
||||
i3_event_state_mask_t event_state_from_str(const char *str);
|
||||
i3_event_state_mask_t event_state_from_str(const char *str) __attribute__((__pure__));
|
||||
|
||||
/** The beginning of the prototype for every cfg_ function. */
|
||||
#define I3_CFG Match *current_match, struct ConfigResultIR *result
|
||||
|
||||
@ -9,23 +9,16 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <xcb/shape.h>
|
||||
#include <xcb/xcb_keysyms.h>
|
||||
#include <xcb/xkb.h>
|
||||
|
||||
#include <X11/XKBlib.h>
|
||||
|
||||
#define SN_API_NOT_YET_FROZEN 1
|
||||
#include <libsn/sn-launcher.h>
|
||||
|
||||
#include "queue.h"
|
||||
#include "data.h"
|
||||
#include "xcb.h"
|
||||
|
||||
/** Git commit identifier, from version.c */
|
||||
extern const char *i3_version;
|
||||
@ -75,5 +68,4 @@ extern xcb_colormap_t colormap;
|
||||
extern bool xkb_supported, shape_supported;
|
||||
extern xcb_window_t root;
|
||||
extern struct ev_loop *main_loop;
|
||||
extern bool only_check_config;
|
||||
extern bool force_xinerama;
|
||||
|
||||
@ -158,7 +158,7 @@ char *sstrndup(const char *str, size_t size);
|
||||
* there is no more memory available)
|
||||
*
|
||||
*/
|
||||
int sasprintf(char **strp, const char *fmt, ...);
|
||||
int sasprintf(char **strp, const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
||||
|
||||
/**
|
||||
* Wrapper around correct write which returns -1 (meaning that
|
||||
@ -186,7 +186,7 @@ ssize_t swrite(int fd, const void *buf, size_t count);
|
||||
* Like strcasecmp but considers the case where either string is NULL.
|
||||
*
|
||||
*/
|
||||
int strcasecmp_nullable(const char *a, const char *b);
|
||||
int strcasecmp_nullable(const char *a, const char *b) __attribute__((pure));
|
||||
|
||||
/**
|
||||
* Build an i3String from an UTF-8 encoded string.
|
||||
@ -504,7 +504,7 @@ void init_dpi(void);
|
||||
* This function returns the value of the DPI setting.
|
||||
*
|
||||
*/
|
||||
long get_dpi_value(void);
|
||||
long get_dpi_value(void) __attribute__((pure));
|
||||
|
||||
/**
|
||||
* Convert a logical amount of pixels (e.g. 2 pixels on a “standard” 96 DPI
|
||||
@ -512,7 +512,7 @@ long get_dpi_value(void);
|
||||
* screen, e.g. 5 pixels on a 227 DPI MacBook Pro 13" Retina screen.
|
||||
*
|
||||
*/
|
||||
int logical_px(const int logical);
|
||||
int logical_px(int logical) __attribute__((pure));
|
||||
|
||||
/**
|
||||
* This function resolves ~ in pathnames.
|
||||
|
||||
@ -35,4 +35,4 @@ void regex_free(struct regex *regex);
|
||||
* be visible without debug logging.
|
||||
*
|
||||
*/
|
||||
bool regex_matches(struct regex *regex, const char *input);
|
||||
bool regex_matches(const struct regex *regex, const char *input);
|
||||
|
||||
@ -56,7 +56,7 @@ void startup_sequence_rename_workspace(const char *old_name, const char *new_nam
|
||||
* Gets the stored startup sequence for the _NET_STARTUP_ID of a given window.
|
||||
*
|
||||
*/
|
||||
struct Startup_Sequence *startup_sequence_get(i3Window *cwindow,
|
||||
struct Startup_Sequence *startup_sequence_get(const i3Window *cwindow,
|
||||
xcb_get_property_reply_t *startup_id_reply, bool ignore_mapped_leader);
|
||||
|
||||
/**
|
||||
@ -68,10 +68,10 @@ struct Startup_Sequence *startup_sequence_get(i3Window *cwindow,
|
||||
* Returns NULL otherwise.
|
||||
*
|
||||
*/
|
||||
char *startup_workspace_for_window(i3Window *cwindow, xcb_get_property_reply_t *startup_id_reply);
|
||||
char *startup_workspace_for_window(const i3Window *cwindow, xcb_get_property_reply_t *startup_id_reply);
|
||||
|
||||
/**
|
||||
* Deletes the startup sequence for a window if it exists.
|
||||
*
|
||||
*/
|
||||
void startup_sequence_delete_by_window(i3Window *win);
|
||||
void startup_sequence_delete_by_window(const i3Window *win);
|
||||
|
||||
@ -9,8 +9,6 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "all.h"
|
||||
|
||||
/**
|
||||
* Tiling drag initiation modes.
|
||||
*/
|
||||
|
||||
@ -71,7 +71,7 @@ Rect rect_sanitize_dimensions(Rect rect);
|
||||
* Returns true if the name consists of only digits.
|
||||
*
|
||||
*/
|
||||
__attribute__((pure)) bool name_is_digits(const char *name);
|
||||
bool name_is_digits(const char *name) __attribute__((__pure__));
|
||||
|
||||
/**
|
||||
* Set 'out' to the layout_t value for the given layout. The function
|
||||
@ -170,28 +170,28 @@ ssize_t slurp(const char *path, char **buf);
|
||||
* Convert a direction to its corresponding orientation.
|
||||
*
|
||||
*/
|
||||
orientation_t orientation_from_direction(direction_t direction);
|
||||
orientation_t orientation_from_direction(direction_t direction) __attribute__((__const__));
|
||||
|
||||
/**
|
||||
* Convert a direction to its corresponding position.
|
||||
*
|
||||
*/
|
||||
position_t position_from_direction(direction_t direction);
|
||||
position_t position_from_direction(direction_t direction) __attribute__((__const__));
|
||||
|
||||
/**
|
||||
* Convert orientation and position to the corresponding direction.
|
||||
*
|
||||
*/
|
||||
direction_t direction_from_orientation_position(orientation_t orientation, position_t position);
|
||||
direction_t direction_from_orientation_position(orientation_t orientation, position_t position) __attribute__((__const__));
|
||||
|
||||
/**
|
||||
* Converts direction to a string representation.
|
||||
*
|
||||
*/
|
||||
const char *direction_to_string(direction_t direction);
|
||||
const char *direction_to_string(direction_t direction) __attribute__((__const__));
|
||||
|
||||
/**
|
||||
* Converts position to a string representation.
|
||||
*
|
||||
*/
|
||||
const char *position_to_string(position_t position);
|
||||
const char *position_to_string(position_t position) __attribute__((__const__));
|
||||
|
||||
@ -101,7 +101,7 @@ void x_push_changes(Con *con);
|
||||
* next call to x_push_changes() will make the change visible in X11.
|
||||
*
|
||||
*/
|
||||
void x_raise_con(Con *con);
|
||||
void x_raise_con(const Con *con);
|
||||
|
||||
/**
|
||||
* Sets the WM_NAME property (so, no UTF8, but used only for debugging anyways)
|
||||
|
||||
@ -12,7 +12,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
|
||||
/* The default visual_type to use if none is specified when creating the surface. Must be defined globally. */
|
||||
extern xcb_visualtype_t *visual_type;
|
||||
@ -83,7 +82,7 @@ static xcb_gcontext_t get_gc(xcb_connection_t *conn, uint8_t depth, xcb_drawable
|
||||
* Get depth of visual specified by visualid
|
||||
*
|
||||
*/
|
||||
uint16_t get_visual_depth(xcb_visualid_t visual_id) {
|
||||
uint16_t get_visual_depth(const xcb_visualid_t visual_id) {
|
||||
xcb_depth_iterator_t depth_iter;
|
||||
|
||||
depth_iter = xcb_screen_allowed_depths_iterator(root_screen);
|
||||
|
||||
@ -102,7 +102,7 @@ Binding *configure_binding(const char *bindtype, const char *modifiers, const ch
|
||||
ELOG("Keybinding has more than one Group specified, but your X server is always in precisely one group. The keybinding can never trigger.\n");
|
||||
}
|
||||
|
||||
struct Mode *mode = mode_from_name(modename, pango_markup);
|
||||
const struct Mode *mode = mode_from_name(modename, pango_markup);
|
||||
TAILQ_INSERT_TAIL(mode->bindings, new_binding, bindings);
|
||||
|
||||
TAILQ_INIT(&(new_binding->keycodes_head));
|
||||
@ -243,7 +243,7 @@ static Binding *get_binding(i3_event_state_mask_t state_filtered, bool is_releas
|
||||
* keycode */
|
||||
bool found_keycode = false;
|
||||
if (input_type == B_KEYBOARD && bind->symbol != NULL) {
|
||||
xcb_keycode_t input_keycode = (xcb_keycode_t)input_code;
|
||||
const xcb_keycode_t input_keycode = (xcb_keycode_t)input_code;
|
||||
struct Binding_Keycode *binding_keycode;
|
||||
TAILQ_FOREACH (binding_keycode, &(bind->keycodes_head), keycodes) {
|
||||
const uint32_t modifiers_mask = (binding_keycode->modifiers & 0x0000FFFF);
|
||||
@ -680,11 +680,11 @@ static int reorder_binding_cmp(const void *a, const void *b) {
|
||||
Binding *second = *((Binding **)b);
|
||||
if (first->event_state_mask < second->event_state_mask) {
|
||||
return 1;
|
||||
} else if (first->event_state_mask == second->event_state_mask) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
if (first->event_state_mask == second->event_state_mask) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void reorder_bindings_of_mode(struct Mode *mode) {
|
||||
@ -907,20 +907,17 @@ CommandResult *run_binding(Binding *bind, Con *con) {
|
||||
}
|
||||
|
||||
static int fill_rmlvo_from_root(struct xkb_rule_names *xkb_names) {
|
||||
xcb_intern_atom_reply_t *atom_reply;
|
||||
size_t content_max_words = 256;
|
||||
|
||||
atom_reply = xcb_intern_atom_reply(
|
||||
xcb_intern_atom_reply_t *atom_reply = xcb_intern_atom_reply(
|
||||
conn, xcb_intern_atom(conn, 0, strlen("_XKB_RULES_NAMES"), "_XKB_RULES_NAMES"), NULL);
|
||||
if (atom_reply == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
xcb_get_property_cookie_t prop_cookie;
|
||||
xcb_get_property_reply_t *prop_reply;
|
||||
prop_cookie = xcb_get_property_unchecked(conn, false, root, atom_reply->atom,
|
||||
XCB_GET_PROPERTY_TYPE_ANY, 0, content_max_words);
|
||||
prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL);
|
||||
xcb_get_property_cookie_t prop_cookie = xcb_get_property_unchecked(conn, false, root, atom_reply->atom,
|
||||
XCB_GET_PROPERTY_TYPE_ANY, 0, content_max_words);
|
||||
xcb_get_property_reply_t *prop_reply = xcb_get_property_reply(conn, prop_cookie, NULL);
|
||||
if (prop_reply == NULL) {
|
||||
free(atom_reply);
|
||||
return -1;
|
||||
@ -945,7 +942,7 @@ static int fill_rmlvo_from_root(struct xkb_rule_names *xkb_names) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *walk = (const char *)xcb_get_property_value(prop_reply);
|
||||
const char *walk = xcb_get_property_value(prop_reply);
|
||||
int remaining = xcb_get_property_value_length(prop_reply);
|
||||
for (int i = 0; i < 5 && remaining > 0; i++) {
|
||||
const int len = strnlen(walk, remaining);
|
||||
|
||||
@ -398,14 +398,14 @@ void handle_button_press(xcb_button_press_event_t *event) {
|
||||
/* If the root window is clicked, find the relevant output from the
|
||||
* click coordinates and focus the output's active workspace. */
|
||||
if (event->event == root && event->response_type == XCB_BUTTON_PRESS) {
|
||||
Con *output, *ws;
|
||||
Con *output;
|
||||
TAILQ_FOREACH (output, &(croot->nodes_head), nodes) {
|
||||
if (con_is_internal(output) ||
|
||||
!rect_contains(output->rect, event->event_x, event->event_y)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ws = TAILQ_FIRST(&(output_get_content(output)->focus_head));
|
||||
Con *ws = TAILQ_FIRST(&(output_get_content(output)->focus_head));
|
||||
if (ws != con_get_workspace(focused)) {
|
||||
workspace_show(ws);
|
||||
tree_render();
|
||||
|
||||
147
src/commands.c
147
src/commands.c
@ -16,7 +16,7 @@
|
||||
|
||||
// Macros to make the YAJL API a bit easier to use.
|
||||
#define y(x, ...) (cmd_output->json_gen != NULL ? yajl_gen_##x(cmd_output->json_gen, ##__VA_ARGS__) : 0)
|
||||
#define ystr(str) (cmd_output->json_gen != NULL ? yajl_gen_string(cmd_output->json_gen, (unsigned char *)str, strlen(str)) : 0)
|
||||
#define ystr(str) (cmd_output->json_gen != NULL ? yajl_gen_string(cmd_output->json_gen, (unsigned char *)(str), strlen((str))) : 0)
|
||||
#define ysuccess(success) \
|
||||
do { \
|
||||
if (cmd_output->json_gen != NULL) { \
|
||||
@ -81,7 +81,7 @@
|
||||
*
|
||||
*/
|
||||
static bool maybe_back_and_forth(struct CommandResultIR *cmd_output, const char *name) {
|
||||
Con *ws = con_get_workspace(focused);
|
||||
const Con *ws = con_get_workspace(focused);
|
||||
|
||||
/* If we switched to a different workspace, do nothing */
|
||||
if (strcmp(ws->name, name) != 0) {
|
||||
@ -101,16 +101,13 @@ static bool maybe_back_and_forth(struct CommandResultIR *cmd_output, const char
|
||||
* forth is enabled, in which case the back_and_forth workspace is returned.
|
||||
*/
|
||||
static Con *maybe_auto_back_and_forth_workspace(Con *workspace) {
|
||||
Con *current, *baf;
|
||||
|
||||
if (!config.workspace_auto_back_and_forth) {
|
||||
return workspace;
|
||||
}
|
||||
|
||||
current = con_get_workspace(focused);
|
||||
|
||||
const Con *current = con_get_workspace(focused);
|
||||
if (current == workspace) {
|
||||
baf = workspace_back_and_forth_get();
|
||||
Con *baf = workspace_back_and_forth_get();
|
||||
if (baf != NULL) {
|
||||
DLOG("Substituting workspace with back_and_forth, as it is focused.\n");
|
||||
return baf;
|
||||
@ -223,7 +220,7 @@ void cmd_criteria_add(I3_CMD, const char *ctype, const char *cvalue) {
|
||||
match_parse_property(current_match, ctype, cvalue);
|
||||
}
|
||||
|
||||
static void move_matches_to_workspace(struct owindows_head *owindows, Con *ws) {
|
||||
static void move_matches_to_workspace(const struct owindows_head *owindows, Con *ws) {
|
||||
owindow *current;
|
||||
TAILQ_FOREACH (current, owindows, owindows) {
|
||||
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
||||
@ -348,7 +345,7 @@ void cmd_move_con_to_workspace_number(I3_CMD, const char *which, const char *no_
|
||||
|
||||
LOG("should move window to workspace %s\n", which);
|
||||
|
||||
long parsed_num = ws_name_to_number(which);
|
||||
const long parsed_num = ws_name_to_number(which);
|
||||
if (parsed_num == -1) {
|
||||
LOG("Could not parse initial part of \"%s\" as a number.\n", which);
|
||||
yerror("Could not parse number \"%s\"", which);
|
||||
@ -378,21 +375,23 @@ void cmd_move_con_to_workspace_number(I3_CMD, const char *which, const char *no_
|
||||
static direction_t parse_direction(const char *str) {
|
||||
if (strcmp(str, "left") == 0) {
|
||||
return D_LEFT;
|
||||
} else if (strcmp(str, "right") == 0) {
|
||||
return D_RIGHT;
|
||||
} else if (strcmp(str, "up") == 0) {
|
||||
return D_UP;
|
||||
} else if (strcmp(str, "down") == 0) {
|
||||
return D_DOWN;
|
||||
} else {
|
||||
ELOG("Invalid direction. This is a parser bug.\n");
|
||||
assert(false);
|
||||
}
|
||||
if (strcmp(str, "right") == 0) {
|
||||
return D_RIGHT;
|
||||
}
|
||||
if (strcmp(str, "up") == 0) {
|
||||
return D_UP;
|
||||
}
|
||||
if (strcmp(str, "down") == 0) {
|
||||
return D_DOWN;
|
||||
}
|
||||
ELOG("Invalid direction. This is a parser bug.\n");
|
||||
assert(false);
|
||||
}
|
||||
|
||||
static void cmd_resize_floating(I3_CMD, const char *direction_str, Con *floating_con, int px) {
|
||||
Rect old_rect = floating_con->rect;
|
||||
Con *focused_con = con_descend_focused(floating_con);
|
||||
const Rect old_rect = floating_con->rect;
|
||||
const Con *focused_con = con_descend_focused(floating_con);
|
||||
|
||||
direction_t direction;
|
||||
if (strcmp(direction_str, "height") == 0) {
|
||||
@ -402,7 +401,7 @@ static void cmd_resize_floating(I3_CMD, const char *direction_str, Con *floating
|
||||
} else {
|
||||
direction = parse_direction(direction_str);
|
||||
}
|
||||
orientation_t orientation = orientation_from_direction(direction);
|
||||
const orientation_t orientation = orientation_from_direction(direction);
|
||||
|
||||
/* ensure that resize will take place even if pixel increment is smaller than
|
||||
* height increment or width increment.
|
||||
@ -449,12 +448,12 @@ static void cmd_resize_floating(I3_CMD, const char *direction_str, Con *floating
|
||||
}
|
||||
}
|
||||
|
||||
static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *direction, int px, int ppt) {
|
||||
static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *direction, int px, const int ppt) {
|
||||
Con *second = NULL;
|
||||
Con *first = current;
|
||||
direction_t search_direction = parse_direction(direction);
|
||||
const direction_t search_direction = parse_direction(direction);
|
||||
|
||||
bool res = resize_find_tiling_participants(&first, &second, search_direction, false);
|
||||
const bool res = resize_find_tiling_participants(&first, &second, search_direction, false);
|
||||
if (!res) {
|
||||
yerror("No second container found in this direction.");
|
||||
return false;
|
||||
@ -468,22 +467,22 @@ static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *direct
|
||||
return resize_neighboring_cons(first, second, px, ppt);
|
||||
}
|
||||
|
||||
static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *direction, int px, double ppt) {
|
||||
static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *direction, const int px, double ppt) {
|
||||
LOG("width/height resize\n");
|
||||
|
||||
/* get the appropriate current container (skip stacked/tabbed cons) */
|
||||
Con *dummy = NULL;
|
||||
direction_t search_direction = (strcmp(direction, "width") == 0 ? D_LEFT : D_DOWN);
|
||||
bool search_result = resize_find_tiling_participants(¤t, &dummy, search_direction, true);
|
||||
const direction_t search_direction = (strcmp(direction, "width") == 0 ? D_LEFT : D_DOWN);
|
||||
const bool search_result = resize_find_tiling_participants(¤t, &dummy, search_direction, true);
|
||||
if (search_result == false) {
|
||||
yerror("Failed to find appropriate tiling containers for resize operation");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* get the default percentage */
|
||||
int children = con_num_children(current->parent);
|
||||
const int children = con_num_children(current->parent);
|
||||
LOG("ins. %d children\n", children);
|
||||
double percentage = 1.0 / children;
|
||||
const double percentage = 1.0 / children;
|
||||
LOG("default percentage = %f\n", percentage);
|
||||
|
||||
/* Ensure all the other children have a percentage set. */
|
||||
@ -496,7 +495,6 @@ static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *dir
|
||||
}
|
||||
|
||||
double new_current_percent;
|
||||
double subtract_percent;
|
||||
if (ppt != 0.0) {
|
||||
new_current_percent = current->percent + ppt;
|
||||
} else {
|
||||
@ -504,7 +502,7 @@ static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *dir
|
||||
ppt = (double)px / (double)con_rect_size_in_orientation(current->parent);
|
||||
new_current_percent = current->percent + ppt;
|
||||
}
|
||||
subtract_percent = ppt / (children - 1);
|
||||
const double subtract_percent = ppt / (children - 1);
|
||||
if (ppt < 0.0 && new_current_percent < percent_for_1px(current)) {
|
||||
yerror("Not resizing, container would end with less than 1px");
|
||||
return false;
|
||||
@ -589,7 +587,7 @@ void cmd_resize(I3_CMD, const char *way, const char *direction, long resize_px,
|
||||
ysuccess(true);
|
||||
}
|
||||
|
||||
static bool resize_set_tiling(I3_CMD, Con *target, orientation_t resize_orientation, bool is_ppt, long target_size) {
|
||||
static bool resize_set_tiling(I3_CMD, Con *target, const orientation_t resize_orientation, const bool is_ppt, const long target_size) {
|
||||
direction_t search_direction;
|
||||
char *mode;
|
||||
if (resize_orientation == HORIZ) {
|
||||
@ -636,7 +634,7 @@ void cmd_resize_set(I3_CMD, long cwidth, const char *mode_width, long cheight, c
|
||||
TAILQ_FOREACH (current, &OWINDOWS, owindows) {
|
||||
Con *floating_con;
|
||||
if ((floating_con = con_inside_floating(current->con))) {
|
||||
Con *output = con_get_output(floating_con);
|
||||
const Con *output = con_get_output(floating_con);
|
||||
if (cwidth == 0) {
|
||||
cwidth = floating_con->rect.width;
|
||||
} else if (mode_width && strcmp(mode_width, "ppt") == 0) {
|
||||
@ -655,12 +653,12 @@ void cmd_resize_set(I3_CMD, long cwidth, const char *mode_width, long cheight, c
|
||||
}
|
||||
|
||||
if (cwidth > 0) {
|
||||
bool is_ppt = mode_width && strcmp(mode_width, "ppt") == 0;
|
||||
const bool is_ppt = mode_width && strcmp(mode_width, "ppt") == 0;
|
||||
success &= resize_set_tiling(current_match, cmd_output, current->con,
|
||||
HORIZ, is_ppt, cwidth);
|
||||
}
|
||||
if (cheight > 0) {
|
||||
bool is_ppt = mode_height && strcmp(mode_height, "ppt") == 0;
|
||||
const bool is_ppt = mode_height && strcmp(mode_height, "ppt") == 0;
|
||||
success &= resize_set_tiling(current_match, cmd_output, current->con,
|
||||
VERT, is_ppt, cheight);
|
||||
}
|
||||
@ -671,7 +669,7 @@ void cmd_resize_set(I3_CMD, long cwidth, const char *mode_width, long cheight, c
|
||||
ysuccess(success);
|
||||
}
|
||||
|
||||
static int border_width_from_style(border_style_t border_style, long border_width, Con *con) {
|
||||
static int border_width_from_style(const border_style_t border_style, const long border_width, Con *con) {
|
||||
if (border_style == BS_NONE) {
|
||||
return 0;
|
||||
}
|
||||
@ -695,7 +693,7 @@ static int border_width_from_style(border_style_t border_style, long border_widt
|
||||
* Implementation of 'border normal|pixel [<n>]', 'border none|1pixel|toggle'.
|
||||
*
|
||||
*/
|
||||
void cmd_border(I3_CMD, const char *border_style_str, long border_width) {
|
||||
void cmd_border(I3_CMD, const char *border_style_str, const long border_width) {
|
||||
DLOG("border style should be changed to %s with border width %ld\n", border_style_str, border_width);
|
||||
owindow *current;
|
||||
|
||||
@ -763,7 +761,7 @@ void cmd_append_layout(I3_CMD, const char *cpath) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
json_content_t content = json_determine_content(buf, len);
|
||||
const json_content_t content = json_determine_content(buf, len);
|
||||
LOG("JSON content = %d\n", content);
|
||||
if (content == JSON_CONTENT_UNKNOWN) {
|
||||
ELOG("Could not determine the contents of \"%s\", not loading.\n", path);
|
||||
@ -787,7 +785,7 @@ void cmd_append_layout(I3_CMD, const char *cpath) {
|
||||
char *errormsg = NULL;
|
||||
tree_append_json(parent, buf, len, &errormsg);
|
||||
if (errormsg != NULL) {
|
||||
yerror(errormsg);
|
||||
yerror("%s", errormsg);
|
||||
free(errormsg);
|
||||
/* Note that we continue executing since tree_append_json() has
|
||||
* side-effects — user-provided layouts can be partly valid, partly
|
||||
@ -859,12 +857,12 @@ void cmd_workspace(I3_CMD, const char *which) {
|
||||
* Implementation of 'workspace [--no-auto-back-and-forth] number <name>'
|
||||
*
|
||||
*/
|
||||
void cmd_workspace_number(I3_CMD, const char *which, const char *_no_auto_back_and_forth) {
|
||||
const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
|
||||
void cmd_workspace_number(I3_CMD, const char *which, const char *no_auto_back_and_forth_str) {
|
||||
const bool no_auto_back_and_forth = (no_auto_back_and_forth_str != NULL);
|
||||
|
||||
disable_global_fullscreen();
|
||||
|
||||
long parsed_num = ws_name_to_number(which);
|
||||
const long parsed_num = ws_name_to_number(which);
|
||||
if (parsed_num == -1) {
|
||||
yerror("Could not parse initial part of \"%s\" as a number.", which);
|
||||
return;
|
||||
@ -907,8 +905,8 @@ void cmd_workspace_back_and_forth(I3_CMD) {
|
||||
* Implementation of 'workspace [--no-auto-back-and-forth] <name>'
|
||||
*
|
||||
*/
|
||||
void cmd_workspace_name(I3_CMD, const char *name, const char *_no_auto_back_and_forth) {
|
||||
const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
|
||||
void cmd_workspace_name(I3_CMD, const char *name, const char *no_auto_back_and_forth_str) {
|
||||
const bool no_auto_back_and_forth = (no_auto_back_and_forth_str != NULL);
|
||||
|
||||
if (strncasecmp(name, "__", strlen("__")) == 0) {
|
||||
yerror("You cannot switch to the i3-internal workspaces (\"%s\").", name);
|
||||
@ -936,7 +934,7 @@ void cmd_workspace_name(I3_CMD, const char *name, const char *_no_auto_back_and_
|
||||
void cmd_mark(I3_CMD, const char *mark, const char *mode, const char *toggle) {
|
||||
HANDLE_EMPTY_MATCH;
|
||||
|
||||
owindow *current = TAILQ_FIRST(&OWINDOWS);
|
||||
const owindow *current = TAILQ_FIRST(&OWINDOWS);
|
||||
if (current == NULL) {
|
||||
yerror("Given criteria don't match a window");
|
||||
return;
|
||||
@ -950,7 +948,7 @@ void cmd_mark(I3_CMD, const char *mark, const char *mode, const char *toggle) {
|
||||
|
||||
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
||||
|
||||
mark_mode_t mark_mode = (mode == NULL || strcmp(mode, "--replace") == 0) ? MM_REPLACE : MM_ADD;
|
||||
const mark_mode_t mark_mode = (mode == NULL || strcmp(mode, "--replace") == 0) ? MM_REPLACE : MM_ADD;
|
||||
if (toggle != NULL) {
|
||||
con_mark_toggle(current->con, mark, mark_mode);
|
||||
} else {
|
||||
@ -1020,10 +1018,9 @@ static void user_output_names_add(user_output_names_head *list, const char *name
|
||||
user_output_name *co = scalloc(sizeof(user_output_name), 1);
|
||||
co->name = sstrdup(name);
|
||||
TAILQ_INSERT_TAIL(list, co, user_output_names);
|
||||
return;
|
||||
}
|
||||
|
||||
static Output *user_output_names_find_next(user_output_names_head *names, Output *current_output) {
|
||||
static Output *user_output_names_find_next(const user_output_names_head *names, Output *current_output) {
|
||||
Output *target_output = NULL;
|
||||
user_output_name *uo;
|
||||
TAILQ_FOREACH (uo, names, user_output_names) {
|
||||
@ -1059,9 +1056,8 @@ static Output *user_output_names_find_next(user_output_names_head *names, Output
|
||||
}
|
||||
|
||||
static void user_output_names_free(user_output_names_head *names) {
|
||||
user_output_name *uo;
|
||||
while (!TAILQ_EMPTY(names)) {
|
||||
uo = TAILQ_FIRST(names);
|
||||
user_output_name *uo = TAILQ_FIRST(names);
|
||||
free(uo->name);
|
||||
TAILQ_REMOVE(names, uo, user_output_names);
|
||||
free(uo);
|
||||
@ -1072,7 +1068,7 @@ static void user_output_names_free(user_output_names_head *names) {
|
||||
* Implementation of 'move [window|container|workspace] [to] output <strings>'.
|
||||
*
|
||||
*/
|
||||
void cmd_move_con_to_output(I3_CMD, const char *name, bool move_workspace) {
|
||||
void cmd_move_con_to_output(I3_CMD, const char *name, const bool move_workspace) {
|
||||
/* Initialize a data structure that is used to save multiple user-specified
|
||||
* output names since this function is called multiple types for each
|
||||
* command call. */
|
||||
@ -1248,7 +1244,7 @@ void cmd_kill(I3_CMD, const char *kill_mode_str) {
|
||||
*
|
||||
*/
|
||||
void cmd_exec(I3_CMD, const char *nosn, const char *command) {
|
||||
bool no_startup_id = (nosn != NULL);
|
||||
const bool no_startup_id = (nosn != NULL);
|
||||
|
||||
HANDLE_EMPTY_MATCH;
|
||||
|
||||
@ -1314,7 +1310,7 @@ void cmd_focus_direction(I3_CMD, const char *direction_str) {
|
||||
continue;
|
||||
}
|
||||
if (auto_direction) {
|
||||
orientation_t o = con_orientation(current->con->parent);
|
||||
const orientation_t o = con_orientation(current->con->parent);
|
||||
direction = direction_from_orientation_position(o, position);
|
||||
}
|
||||
tree_next(current->con, direction);
|
||||
@ -1376,7 +1372,7 @@ void cmd_focus_window_mode(I3_CMD, const char *window_mode) {
|
||||
to_floating = false;
|
||||
}
|
||||
|
||||
Con *ws = con_get_workspace(focused);
|
||||
const Con *ws = con_get_workspace(focused);
|
||||
Con *current;
|
||||
bool success = false;
|
||||
TAILQ_FOREACH (current, &(ws->focus_head), focused) {
|
||||
@ -1432,7 +1428,7 @@ void cmd_focus_level(I3_CMD, const char *level) {
|
||||
* Implementation of 'focus'.
|
||||
*
|
||||
*/
|
||||
void cmd_focus(I3_CMD, bool focus_workspace) {
|
||||
void cmd_focus(I3_CMD, const bool focus_workspace) {
|
||||
DLOG("current_match = %p\n", current_match);
|
||||
|
||||
if (match_is_empty(current_match)) {
|
||||
@ -1448,7 +1444,7 @@ void cmd_focus(I3_CMD, bool focus_workspace) {
|
||||
|
||||
CMD_FOCUS_WARN_CHILDREN;
|
||||
|
||||
Con *__i3_scratch = workspace_get("__i3_scratch");
|
||||
const Con *__i3_scratch = workspace_get("__i3_scratch");
|
||||
owindow *current;
|
||||
TAILQ_FOREACH (current, &OWINDOWS, owindows) {
|
||||
Con *ws = con_get_workspace(current->con);
|
||||
@ -1488,7 +1484,7 @@ void cmd_focus(I3_CMD, bool focus_workspace) {
|
||||
*
|
||||
*/
|
||||
void cmd_fullscreen(I3_CMD, const char *action, const char *fullscreen_mode) {
|
||||
fullscreen_mode_t mode = strcmp(fullscreen_mode, "global") == 0 ? CF_GLOBAL : CF_OUTPUT;
|
||||
const fullscreen_mode_t mode = strcmp(fullscreen_mode, "global") == 0 ? CF_GLOBAL : CF_OUTPUT;
|
||||
DLOG("%s fullscreen, mode = %s\n", action, fullscreen_mode);
|
||||
owindow *current;
|
||||
|
||||
@ -1553,11 +1549,11 @@ void cmd_sticky(I3_CMD, const char *action) {
|
||||
* Implementation of 'move <direction> [<amount> [px|ppt]]'.
|
||||
*
|
||||
*/
|
||||
void cmd_move_direction(I3_CMD, const char *direction_str, long amount, const char *mode) {
|
||||
void cmd_move_direction(I3_CMD, const char *direction_str, const long amount, const char *mode) {
|
||||
owindow *current;
|
||||
HANDLE_EMPTY_MATCH;
|
||||
|
||||
direction_t direction = parse_direction(direction_str);
|
||||
const direction_t direction = parse_direction(direction_str);
|
||||
|
||||
const bool is_ppt = mode && strcmp(mode, "ppt") == 0;
|
||||
|
||||
@ -1566,7 +1562,7 @@ void cmd_move_direction(I3_CMD, const char *direction_str, long amount, const ch
|
||||
if (con_is_floating(current->con)) {
|
||||
DLOG("floating move with %ld %s\n", amount, mode);
|
||||
Rect newrect = current->con->parent->rect;
|
||||
Con *output = con_get_output(current->con);
|
||||
const Con *output = con_get_output(current->con);
|
||||
|
||||
switch (direction) {
|
||||
case D_LEFT:
|
||||
@ -1630,8 +1626,6 @@ void cmd_layout(I3_CMD, const char *layout_str) {
|
||||
*
|
||||
*/
|
||||
void cmd_layout_toggle(I3_CMD, const char *toggle_mode) {
|
||||
owindow *current;
|
||||
|
||||
if (toggle_mode == NULL) {
|
||||
toggle_mode = "default";
|
||||
}
|
||||
@ -1642,6 +1636,7 @@ void cmd_layout_toggle(I3_CMD, const char *toggle_mode) {
|
||||
if (match_is_empty(current_match)) {
|
||||
con_toggle_layout(focused, toggle_mode);
|
||||
} else {
|
||||
owindow *current;
|
||||
TAILQ_FOREACH (current, &OWINDOWS, owindows) {
|
||||
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
||||
con_toggle_layout(current->con, toggle_mode);
|
||||
@ -1783,7 +1778,7 @@ void cmd_focus_output(I3_CMD, const char *name) {
|
||||
}
|
||||
|
||||
Output *current_output = get_output_for_con(con);
|
||||
Output *target_output = user_output_names_find_next(&names, current_output);
|
||||
const Output *target_output = user_output_names_find_next(&names, current_output);
|
||||
user_output_names_free(&names);
|
||||
bool success = false;
|
||||
if (target_output) {
|
||||
@ -1812,7 +1807,7 @@ void cmd_focus_output(I3_CMD, const char *name) {
|
||||
* Implementation of 'move [window|container] [to] [absolute] position [<pos_x> [px|ppt] <pos_y> [px|ppt]]
|
||||
*
|
||||
*/
|
||||
void cmd_move_window_to_position(I3_CMD, long x, const char *mode_x, long y, const char *mode_y) {
|
||||
void cmd_move_window_to_position(I3_CMD, const long x, const char *mode_x, const long y, const char *mode_y) {
|
||||
bool has_error = false;
|
||||
|
||||
owindow *current;
|
||||
@ -1831,7 +1826,7 @@ void cmd_move_window_to_position(I3_CMD, long x, const char *mode_x, long y, con
|
||||
}
|
||||
|
||||
Rect newrect = current->con->parent->rect;
|
||||
Con *output = con_get_output(current->con);
|
||||
const Con *output = con_get_output(current->con);
|
||||
|
||||
newrect.x = mode_x && strcmp(mode_x, "ppt") == 0 ? output->rect.width * ((double)x / 100.0) : x;
|
||||
newrect.y = mode_y && strcmp(mode_y, "ppt") == 0 ? output->rect.height * ((double)y / 100.0) : y;
|
||||
@ -1943,12 +1938,12 @@ void cmd_move_scratchpad(I3_CMD) {
|
||||
*/
|
||||
void cmd_scratchpad_show(I3_CMD) {
|
||||
DLOG("should show scratchpad window\n");
|
||||
owindow *current;
|
||||
bool result = false;
|
||||
|
||||
if (match_is_empty(current_match)) {
|
||||
result = scratchpad_show(NULL);
|
||||
} else {
|
||||
owindow *current;
|
||||
TAILQ_FOREACH (current, &OWINDOWS, owindows) {
|
||||
DLOG("matching: %p / %s\n", current->con, current->con->name);
|
||||
result |= scratchpad_show(current->con);
|
||||
@ -2011,7 +2006,7 @@ void cmd_swap(I3_CMD, const char *mode, const char *arg) {
|
||||
}
|
||||
|
||||
DLOG("Swapping %p with %p.\n", match->con, con);
|
||||
bool result = con_swap(match->con, con);
|
||||
const bool result = con_swap(match->con, con);
|
||||
|
||||
cmd_output->needs_tree_render = true;
|
||||
// XXX: default reply for now, make this a better reply
|
||||
@ -2138,7 +2133,7 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
|
||||
return;
|
||||
}
|
||||
|
||||
Con *check_dest = get_existing_workspace_by_name(new_name);
|
||||
const Con *check_dest = get_existing_workspace_by_name(new_name);
|
||||
|
||||
/* If check_dest == workspace, the user might be changing the case of the
|
||||
* workspace, or it might just be a no-op. */
|
||||
@ -2158,7 +2153,7 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
|
||||
|
||||
/* By re-attaching, the sort order will be correct afterwards. */
|
||||
Con *previously_focused = focused;
|
||||
Con *previously_focused_content = focused->type == CT_WORKSPACE ? focused->parent : NULL;
|
||||
const Con *previously_focused_content = focused->type == CT_WORKSPACE ? focused->parent : NULL;
|
||||
Con *parent = workspace->parent;
|
||||
con_detach(workspace);
|
||||
con_attach(workspace, parent, false);
|
||||
@ -2176,9 +2171,9 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
|
||||
* Instead, we loop through the available workspaces and only focus
|
||||
* previously_focused if we still find it. */
|
||||
if (previously_focused_content) {
|
||||
Con *workspace = NULL;
|
||||
GREP_FIRST(workspace, previously_focused_content, child == previously_focused);
|
||||
can_restore_focus &= (workspace != NULL);
|
||||
const Con *ws = NULL;
|
||||
GREP_FIRST(ws, previously_focused_content, child == previously_focused);
|
||||
can_restore_focus &= (ws != NULL);
|
||||
}
|
||||
|
||||
if (can_restore_focus) {
|
||||
@ -2356,7 +2351,7 @@ void cmd_shmlog(I3_CMD, const char *argument) {
|
||||
*
|
||||
*/
|
||||
void cmd_debuglog(I3_CMD, const char *argument) {
|
||||
bool logging = get_debug_logging();
|
||||
const bool logging = get_debug_logging();
|
||||
if (!strcmp(argument, "toggle")) {
|
||||
LOG("%s debug logging\n", logging ? "Disabling" : "Enabling");
|
||||
set_debug_logging(!logging);
|
||||
@ -2393,7 +2388,7 @@ static int *gaps_right(gaps_t *gaps) {
|
||||
|
||||
typedef int *(*gap_accessor)(gaps_t *);
|
||||
|
||||
static bool gaps_update(gap_accessor get, const char *scope, const char *mode, int pixels) {
|
||||
static bool gaps_update(const gap_accessor get, const char *scope, const char *mode, const int pixels) {
|
||||
DLOG("gaps_update(scope=%s, mode=%s, pixels=%d)\n", scope, mode, pixels);
|
||||
Con *workspace = con_get_workspace(focused);
|
||||
|
||||
@ -2440,7 +2435,7 @@ static bool gaps_update(gap_accessor get, const char *scope, const char *mode, i
|
||||
Con *output = NULL;
|
||||
TAILQ_FOREACH (output, &(croot->nodes_head), nodes) {
|
||||
Con *cur_ws = NULL;
|
||||
Con *content = output_get_content(output);
|
||||
const Con *content = output_get_content(output);
|
||||
TAILQ_FOREACH (cur_ws, &(content->nodes_head), nodes) {
|
||||
int *gaps_value = get(&(cur_ws->gaps));
|
||||
DLOG("current gaps_value = %d\n", *gaps_value);
|
||||
@ -2478,7 +2473,7 @@ static bool gaps_update(gap_accessor get, const char *scope, const char *mode, i
|
||||
*
|
||||
*/
|
||||
void cmd_gaps(I3_CMD, const char *type, const char *scope, const char *mode, const char *value) {
|
||||
int pixels = logical_px(atoi(value));
|
||||
const int pixels = logical_px(atoi(value));
|
||||
|
||||
if (!strcmp(type, "inner")) {
|
||||
if (!gaps_update(gaps_inner, scope, mode, pixels)) {
|
||||
|
||||
25
src/con.c
25
src/con.c
@ -345,12 +345,11 @@ void con_close(Con *con, kill_window_t kill_window) {
|
||||
|
||||
if (con->type == CT_WORKSPACE) {
|
||||
DLOG("con = %p is a workspace, closing all children instead.\n", con);
|
||||
Con *child, *nextchild;
|
||||
for (child = TAILQ_FIRST(&(con->focus_head)); child;) {
|
||||
nextchild = TAILQ_NEXT(child, focused);
|
||||
for (Con *child = TAILQ_FIRST(&(con->focus_head)); child;) {
|
||||
Con *next_child = TAILQ_NEXT(child, focused);
|
||||
DLOG("killing child = %p.\n", child);
|
||||
tree_close_internal(child, kill_window, false);
|
||||
child = nextchild;
|
||||
child = next_child;
|
||||
}
|
||||
|
||||
return;
|
||||
@ -597,8 +596,6 @@ struct bfs_entry {
|
||||
*
|
||||
*/
|
||||
Con *con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode) {
|
||||
Con *current, *child;
|
||||
|
||||
/* TODO: is breadth-first-search really appropriate? (check as soon as
|
||||
* fullscreen levels and fullscreen for containers is implemented) */
|
||||
TAILQ_HEAD(bfs_head, bfs_entry) bfs_head = TAILQ_HEAD_INITIALIZER(bfs_head);
|
||||
@ -608,7 +605,7 @@ Con *con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode) {
|
||||
|
||||
while (!TAILQ_EMPTY(&bfs_head)) {
|
||||
entry = TAILQ_FIRST(&bfs_head);
|
||||
current = entry->con;
|
||||
Con *current = entry->con;
|
||||
if (current != con && current->fullscreen_mode == fullscreen_mode) {
|
||||
/* empty the queue */
|
||||
while (!TAILQ_EMPTY(&bfs_head)) {
|
||||
@ -622,6 +619,7 @@ Con *con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode) {
|
||||
TAILQ_REMOVE(&bfs_head, entry, entries);
|
||||
free(entry);
|
||||
|
||||
Con *child;
|
||||
TAILQ_FOREACH (child, &(current->nodes_head), nodes) {
|
||||
entry = smalloc(sizeof(struct bfs_entry));
|
||||
entry->con = child;
|
||||
@ -894,9 +892,8 @@ void con_mark(Con *con, const char *mark, mark_mode_t mode) {
|
||||
if (mode == MM_REPLACE) {
|
||||
DLOG("Removing all existing marks on con = %p.\n", con);
|
||||
|
||||
mark_t *current;
|
||||
while (!TAILQ_EMPTY(&(con->marks_head))) {
|
||||
current = TAILQ_FIRST(&(con->marks_head));
|
||||
const mark_t *current = TAILQ_FIRST(&(con->marks_head));
|
||||
con_unmark(con, current->name);
|
||||
}
|
||||
}
|
||||
@ -929,9 +926,8 @@ void con_unmark(Con *con, const char *name) {
|
||||
continue;
|
||||
}
|
||||
|
||||
mark_t *mark;
|
||||
while (!TAILQ_EMPTY(&(current->marks_head))) {
|
||||
mark = TAILQ_FIRST(&(current->marks_head));
|
||||
mark_t *mark = TAILQ_FIRST(&(current->marks_head));
|
||||
FREE(mark->name);
|
||||
TAILQ_REMOVE(&(current->marks_head), mark, marks);
|
||||
FREE(mark);
|
||||
@ -1331,9 +1327,8 @@ static bool _con_move_to_con(Con *con, Con *target, bool behind_focused, bool fi
|
||||
|
||||
if (con->type == CT_WORKSPACE) {
|
||||
/* Re-parent all of the old workspace's floating windows. */
|
||||
Con *child;
|
||||
while (!TAILQ_EMPTY(&(source_ws->floating_head))) {
|
||||
child = TAILQ_FIRST(&(source_ws->floating_head));
|
||||
Con *child = TAILQ_FIRST(&(source_ws->floating_head));
|
||||
con_move_to_workspace(child, target_ws, true, true, false);
|
||||
}
|
||||
|
||||
@ -2043,9 +2038,8 @@ void con_set_layout(Con *con, layout_t layout) {
|
||||
Con **focus_order = get_focus_order(con);
|
||||
|
||||
DLOG("Moving cons\n");
|
||||
Con *child;
|
||||
while (!TAILQ_EMPTY(&(con->nodes_head))) {
|
||||
child = TAILQ_FIRST(&(con->nodes_head));
|
||||
Con *child = TAILQ_FIRST(&(con->nodes_head));
|
||||
con_detach(child);
|
||||
con_attach(child, new, true);
|
||||
}
|
||||
@ -2248,7 +2242,6 @@ static void con_on_remove_child(Con *con) {
|
||||
if (children == 0) {
|
||||
DLOG("Container empty, closing\n");
|
||||
tree_close_internal(con, DONT_KILL_WINDOW, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
15
src/config.c
15
src/config.c
@ -11,8 +11,6 @@
|
||||
#include "all.h"
|
||||
|
||||
#include <libgen.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
char *current_configpath = NULL;
|
||||
@ -42,9 +40,8 @@ static void free_configuration(void) {
|
||||
/* First ungrab the keys */
|
||||
ungrab_all_keys(conn);
|
||||
|
||||
struct Mode *mode;
|
||||
while (!SLIST_EMPTY(&modes)) {
|
||||
mode = SLIST_FIRST(&modes);
|
||||
struct Mode *mode = SLIST_FIRST(&modes);
|
||||
FREE(mode->name);
|
||||
|
||||
/* Clear the old binding list */
|
||||
@ -60,7 +57,7 @@ static void free_configuration(void) {
|
||||
}
|
||||
|
||||
while (!TAILQ_EMPTY(&assignments)) {
|
||||
struct Assignment *assign = TAILQ_FIRST(&assignments);
|
||||
Assignment *assign = TAILQ_FIRST(&assignments);
|
||||
if (assign->type == A_TO_WORKSPACE || assign->type == A_TO_WORKSPACE_NUMBER) {
|
||||
FREE(assign->dest.workspace);
|
||||
} else if (assign->type == A_COMMAND) {
|
||||
@ -82,9 +79,8 @@ static void free_configuration(void) {
|
||||
}
|
||||
|
||||
/* Clear bar configs */
|
||||
Barconfig *barconfig;
|
||||
while (!TAILQ_EMPTY(&barconfigs)) {
|
||||
barconfig = TAILQ_FIRST(&barconfigs);
|
||||
Barconfig *barconfig = TAILQ_FIRST(&barconfigs);
|
||||
FREE(barconfig->id);
|
||||
for (int c = 0; c < barconfig->num_outputs; c++) {
|
||||
free(barconfig->outputs[c]);
|
||||
@ -263,8 +259,7 @@ bool load_configuration(const char *override_configpath, config_load_t load_type
|
||||
TAILQ_INSERT_TAIL(&included_files, file, files);
|
||||
|
||||
LOG("Parsing configfile %s\n", resolved_path);
|
||||
struct stack stack;
|
||||
memset(&stack, '\0', sizeof(struct stack));
|
||||
struct stack stack = {0};
|
||||
struct parser_ctx ctx = {
|
||||
.use_nagbar = (load_type != C_VALIDATE),
|
||||
.stack = &stack,
|
||||
@ -286,8 +281,8 @@ bool load_configuration(const char *override_configpath, config_load_t load_type
|
||||
}
|
||||
|
||||
/* Make bar config blocks without a configured font use the i3-wide font. */
|
||||
Barconfig *current;
|
||||
if (load_type != C_VALIDATE) {
|
||||
Barconfig *current;
|
||||
TAILQ_FOREACH (current, &barconfigs, configs) {
|
||||
if (current->font != NULL) {
|
||||
continue;
|
||||
|
||||
@ -294,19 +294,26 @@ static void create_gaps_assignment(const char *workspace, const gaps_mask_t mask
|
||||
static gaps_mask_t gaps_scope_to_mask(const char *scope) {
|
||||
if (!strcmp(scope, "inner")) {
|
||||
return GAPS_INNER;
|
||||
} else if (!strcmp(scope, "outer")) {
|
||||
}
|
||||
if (!strcmp(scope, "outer")) {
|
||||
return GAPS_OUTER;
|
||||
} else if (!strcmp(scope, "vertical")) {
|
||||
}
|
||||
if (!strcmp(scope, "vertical")) {
|
||||
return GAPS_VERTICAL;
|
||||
} else if (!strcmp(scope, "horizontal")) {
|
||||
}
|
||||
if (!strcmp(scope, "horizontal")) {
|
||||
return GAPS_HORIZONTAL;
|
||||
} else if (!strcmp(scope, "top")) {
|
||||
}
|
||||
if (!strcmp(scope, "top")) {
|
||||
return GAPS_TOP;
|
||||
} else if (!strcmp(scope, "right")) {
|
||||
}
|
||||
if (!strcmp(scope, "right")) {
|
||||
return GAPS_RIGHT;
|
||||
} else if (!strcmp(scope, "bottom")) {
|
||||
}
|
||||
if (!strcmp(scope, "bottom")) {
|
||||
return GAPS_BOTTOM;
|
||||
} else if (!strcmp(scope, "left")) {
|
||||
}
|
||||
if (!strcmp(scope, "left")) {
|
||||
return GAPS_LEFT;
|
||||
}
|
||||
ELOG("Invalid command, cannot process scope %s", scope);
|
||||
@ -941,7 +948,7 @@ CFGFUN(bar_strip_workspace_name, const char *value) {
|
||||
}
|
||||
|
||||
CFGFUN(bar_start) {
|
||||
current_bar = scalloc(1, sizeof(struct Barconfig));
|
||||
current_bar = scalloc(1, sizeof(Barconfig));
|
||||
TAILQ_INIT(&(current_bar->bar_bindings));
|
||||
TAILQ_INIT(&(current_bar->tray_outputs));
|
||||
current_bar->tray_padding = 2;
|
||||
|
||||
@ -121,7 +121,7 @@ void display_running_version(void) {
|
||||
|
||||
yajl_handle handle = yajl_alloc(&version_callbacks, NULL, NULL);
|
||||
|
||||
yajl_status state = yajl_parse(handle, (const unsigned char *)reply, (int)reply_length);
|
||||
yajl_status state = yajl_parse(handle, reply, (int)reply_length);
|
||||
if (state != yajl_status_ok) {
|
||||
errx(EXIT_FAILURE, "Could not parse my own reply. That's weird. reply is %.*s", (int)reply_length, reply);
|
||||
}
|
||||
|
||||
36
src/drag.c
36
src/drag.c
@ -155,7 +155,7 @@ static bool drain_drag_events(EV_P, struct drag_x11_cb *dragloop) {
|
||||
}
|
||||
|
||||
static void xcb_drag_prepare_cb(EV_P_ ev_prepare *w, int revents) {
|
||||
struct drag_x11_cb *dragloop = (struct drag_x11_cb *)w->data;
|
||||
struct drag_x11_cb *dragloop = w->data;
|
||||
while (!drain_drag_events(EV_A, dragloop)) {
|
||||
/* repeatedly drain events: draining might produce additional ones */
|
||||
}
|
||||
@ -177,22 +177,21 @@ drag_result_t drag_pointer(Con *con, const xcb_button_press_event_t *event,
|
||||
xcb_window_t confine_to, int cursor,
|
||||
bool use_threshold, callback_t callback,
|
||||
const void *extra) {
|
||||
xcb_cursor_t xcursor = cursor ? xcursor_get_cursor(cursor) : XCB_NONE;
|
||||
const xcb_cursor_t xcursor = cursor ? xcursor_get_cursor(cursor) : XCB_NONE;
|
||||
|
||||
/* Grab the pointer */
|
||||
xcb_grab_pointer_cookie_t cookie;
|
||||
xcb_grab_pointer_reply_t *reply;
|
||||
xcb_generic_error_t *error;
|
||||
|
||||
cookie = xcb_grab_pointer(conn,
|
||||
false, /* get all pointer events specified by the following mask */
|
||||
root, /* grab the root window */
|
||||
XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION, /* which events to let through */
|
||||
XCB_GRAB_MODE_ASYNC, /* pointer events should continue as normal */
|
||||
XCB_GRAB_MODE_ASYNC, /* keyboard mode */
|
||||
confine_to, /* confine_to = in which window should the cursor stay */
|
||||
use_threshold ? XCB_NONE : xcursor, /* possibly display a special cursor */
|
||||
XCB_CURRENT_TIME);
|
||||
xcb_grab_pointer_cookie_t cookie = xcb_grab_pointer(conn,
|
||||
false, /* get all pointer events specified by the following mask */
|
||||
root, /* grab the root window */
|
||||
XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION, /* which events to let through */
|
||||
XCB_GRAB_MODE_ASYNC, /* pointer events should continue as normal */
|
||||
XCB_GRAB_MODE_ASYNC, /* keyboard mode */
|
||||
confine_to, /* confine_to = in which window should the cursor stay */
|
||||
use_threshold ? XCB_NONE : xcursor, /* possibly display a special cursor */
|
||||
XCB_CURRENT_TIME);
|
||||
|
||||
if ((reply = xcb_grab_pointer_reply(conn, cookie, &error)) == NULL) {
|
||||
ELOG("Could not grab pointer (error_code = %d)\n", error->error_code);
|
||||
@ -203,15 +202,14 @@ drag_result_t drag_pointer(Con *con, const xcb_button_press_event_t *event,
|
||||
free(reply);
|
||||
|
||||
/* Grab the keyboard */
|
||||
xcb_grab_keyboard_cookie_t keyb_cookie;
|
||||
xcb_grab_keyboard_reply_t *keyb_reply;
|
||||
|
||||
keyb_cookie = xcb_grab_keyboard(conn,
|
||||
false, /* get all keyboard events */
|
||||
root, /* grab the root window */
|
||||
XCB_CURRENT_TIME,
|
||||
XCB_GRAB_MODE_ASYNC, /* continue processing pointer events as normal */
|
||||
XCB_GRAB_MODE_ASYNC /* keyboard mode */
|
||||
xcb_grab_keyboard_cookie_t keyb_cookie = xcb_grab_keyboard(conn,
|
||||
false, /* get all keyboard events */
|
||||
root, /* grab the root window */
|
||||
XCB_CURRENT_TIME,
|
||||
XCB_GRAB_MODE_ASYNC, /* continue processing pointer events as normal */
|
||||
XCB_GRAB_MODE_ASYNC /* keyboard mode */
|
||||
);
|
||||
|
||||
if ((keyb_reply = xcb_grab_keyboard_reply(conn, keyb_cookie, &error)) == NULL) {
|
||||
|
||||
@ -77,7 +77,6 @@ void floating_check_size(Con *floating_con, bool prefer_height) {
|
||||
/* Define reasonable minimal and maximal sizes for floating windows */
|
||||
const int floating_sane_min_height = 50;
|
||||
const int floating_sane_min_width = 75;
|
||||
Rect floating_sane_max_dimensions;
|
||||
Con *focused_con = con_descend_focused(floating_con);
|
||||
|
||||
DLOG("deco_rect.height = %d\n", focused_con->deco_rect.height);
|
||||
@ -148,7 +147,7 @@ void floating_check_size(Con *floating_con, bool prefer_height) {
|
||||
* this case according to the ICCCM. */
|
||||
double width = floating_con->rect.width - window->base_width - border_rect.width;
|
||||
double height = floating_con->rect.height - window->base_height - border_rect.height;
|
||||
const double ar = (double)width / (double)height;
|
||||
const double ar = width / height;
|
||||
double new_ar = -1;
|
||||
if (min_ar > 0 && ar < min_ar) {
|
||||
new_ar = min_ar;
|
||||
@ -208,7 +207,7 @@ void floating_check_size(Con *floating_con, bool prefer_height) {
|
||||
/* Unless user requests otherwise (-1), ensure width/height do not exceed
|
||||
* configured maxima or, if unconfigured, limit to combined width of all
|
||||
* outputs */
|
||||
floating_sane_max_dimensions = total_outputs_dimensions();
|
||||
Rect floating_sane_max_dimensions = total_outputs_dimensions();
|
||||
if (config.floating_maximum_height != -1) {
|
||||
floating_con->rect.height -= border_rect.height;
|
||||
if (config.floating_maximum_height == 0) {
|
||||
|
||||
@ -280,10 +280,8 @@ static void handle_mapping_notify(xcb_mapping_notify_event_t *event) {
|
||||
* A new window appeared on the screen (=was mapped), so let’s manage it.
|
||||
*
|
||||
*/
|
||||
static void handle_map_request(xcb_map_request_event_t *event) {
|
||||
xcb_get_window_attributes_cookie_t cookie;
|
||||
|
||||
cookie = xcb_get_window_attributes_unchecked(conn, event->window);
|
||||
static void handle_map_request(const xcb_map_request_event_t *event) {
|
||||
xcb_get_window_attributes_cookie_t cookie = xcb_get_window_attributes_unchecked(conn, event->window);
|
||||
|
||||
DLOG("window = 0x%08x, serial is %d.\n", event->window, event->sequence);
|
||||
add_ignore_event(event->sequence, -1);
|
||||
@ -629,7 +627,7 @@ static bool handle_windowname_change_legacy(Con *con, xcb_get_property_reply_t *
|
||||
static bool handle_windowrole_change(Con *con, xcb_get_property_reply_t *prop) {
|
||||
window_update_role(con->window, prop);
|
||||
|
||||
con = remanage_window(con);
|
||||
remanage_window(con);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
46
src/ipc.c
46
src/ipc.c
@ -28,7 +28,7 @@ char *current_socketpath = NULL;
|
||||
TAILQ_HEAD(ipc_client_head, ipc_client) all_clients = TAILQ_HEAD_INITIALIZER(all_clients);
|
||||
|
||||
static void ipc_client_timeout(EV_P_ ev_timer *w, int revents);
|
||||
static void ipc_socket_writeable_cb(EV_P_ struct ev_io *w, int revents);
|
||||
static void ipc_socket_writeable_cb(EV_P_ ev_io *w, int revents);
|
||||
|
||||
static ev_tstamp kill_timeout = 10.0;
|
||||
|
||||
@ -66,7 +66,7 @@ static void ipc_push_pending(ipc_client *client) {
|
||||
ev_io_start(main_loop, client->write_callback);
|
||||
|
||||
if (!client->timeout) {
|
||||
struct ev_timer *timeout = scalloc(1, sizeof(struct ev_timer));
|
||||
ev_timer *timeout = scalloc(1, sizeof(struct ev_timer));
|
||||
ev_timer_init(timeout, ipc_client_timeout, kill_timeout, 0.);
|
||||
timeout->data = client;
|
||||
client->timeout = timeout;
|
||||
@ -192,9 +192,8 @@ static void ipc_send_shutdown_event(shutdown_reason_t reason) {
|
||||
void ipc_shutdown(shutdown_reason_t reason, int exempt_fd) {
|
||||
ipc_send_shutdown_event(reason);
|
||||
|
||||
ipc_client *current;
|
||||
while (!TAILQ_EMPTY(&all_clients)) {
|
||||
current = TAILQ_FIRST(&all_clients);
|
||||
ipc_client *current = TAILQ_FIRST(&all_clients);
|
||||
if (current->fd != exempt_fd) {
|
||||
shutdown(current->fd, SHUT_RDWR);
|
||||
}
|
||||
@ -359,7 +358,7 @@ static void dump_binding(yajl_gen gen, Binding *bind) {
|
||||
y(map_close);
|
||||
}
|
||||
|
||||
void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
||||
void dump_node(yajl_gen gen, Con *con, bool inplace_restart) {
|
||||
y(map_open);
|
||||
ystr("id");
|
||||
y(integer, (uintptr_t)con);
|
||||
@ -1235,20 +1234,15 @@ static int add_subscription(void *extra, const unsigned char *s,
|
||||
*
|
||||
*/
|
||||
IPC_HANDLER(subscribe) {
|
||||
yajl_handle p;
|
||||
yajl_status stat;
|
||||
|
||||
/* Setup the JSON parser */
|
||||
static yajl_callbacks callbacks = {
|
||||
.yajl_string = add_subscription,
|
||||
};
|
||||
|
||||
p = yalloc(&callbacks, (void *)client);
|
||||
stat = yajl_parse(p, (const unsigned char *)message, message_size);
|
||||
const yajl_handle p = yalloc(&callbacks, client);
|
||||
const yajl_status stat = yajl_parse(p, message, message_size);
|
||||
if (stat != yajl_status_ok) {
|
||||
unsigned char *err;
|
||||
err = yajl_get_error(p, true, (const unsigned char *)message,
|
||||
message_size);
|
||||
unsigned char *err = yajl_get_error(p, true, message, message_size);
|
||||
ELOG("YAJL parse error: %s\n", err);
|
||||
yajl_free_error(p, err);
|
||||
|
||||
@ -1371,24 +1365,18 @@ static int _sync_json_int(void *extra, long long val) {
|
||||
}
|
||||
|
||||
IPC_HANDLER(sync) {
|
||||
yajl_handle p;
|
||||
yajl_status stat;
|
||||
|
||||
/* Setup the JSON parser */
|
||||
static yajl_callbacks callbacks = {
|
||||
.yajl_map_key = _sync_json_key,
|
||||
.yajl_integer = _sync_json_int,
|
||||
};
|
||||
|
||||
struct sync_state state;
|
||||
memset(&state, '\0', sizeof(struct sync_state));
|
||||
p = yalloc(&callbacks, (void *)&state);
|
||||
stat = yajl_parse(p, (const unsigned char *)message, message_size);
|
||||
struct sync_state state = {0};
|
||||
yajl_handle p = yalloc(&callbacks, &state);
|
||||
yajl_status stat = yajl_parse(p, message, message_size);
|
||||
FREE(state.last_key);
|
||||
if (stat != yajl_status_ok) {
|
||||
unsigned char *err;
|
||||
err = yajl_get_error(p, true, (const unsigned char *)message,
|
||||
message_size);
|
||||
unsigned char *err = yajl_get_error(p, true, message, message_size);
|
||||
ELOG("YAJL parse error: %s\n", err);
|
||||
yajl_free_error(p, err);
|
||||
|
||||
@ -1451,11 +1439,11 @@ handler_t handlers[13] = {
|
||||
* at the moment.
|
||||
*
|
||||
*/
|
||||
static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) {
|
||||
static void ipc_receive_message(EV_P_ ev_io *w, int revents) {
|
||||
uint32_t message_type;
|
||||
uint32_t message_length;
|
||||
uint8_t *message = NULL;
|
||||
ipc_client *client = (ipc_client *)w->data;
|
||||
ipc_client *client = w->data;
|
||||
assert(client->fd == w->fd);
|
||||
|
||||
int ret = ipc_recv_message(w->fd, &message_type, &message_length, &message);
|
||||
@ -1487,7 +1475,7 @@ static void ipc_receive_message(EV_P_ struct ev_io *w, int revents) {
|
||||
static void ipc_client_timeout(EV_P_ ev_timer *w, int revents) {
|
||||
/* No need to be polite and check for writeability, the other callback would
|
||||
* have been called by now. */
|
||||
ipc_client *client = (ipc_client *)w->data;
|
||||
ipc_client *client = w->data;
|
||||
|
||||
char *cmdline = NULL;
|
||||
#if defined(__linux__) && defined(SO_PEERCRED)
|
||||
@ -1547,7 +1535,7 @@ static void ipc_socket_writeable_cb(EV_P_ ev_io *w, int revents) {
|
||||
* the list of clients.
|
||||
*
|
||||
*/
|
||||
void ipc_new_client(EV_P_ struct ev_io *w, int revents) {
|
||||
void ipc_new_client(EV_P_ ev_io *w, int revents) {
|
||||
struct sockaddr_un peer;
|
||||
socklen_t len = sizeof(struct sockaddr_un);
|
||||
int fd;
|
||||
@ -1578,12 +1566,12 @@ ipc_client *ipc_new_client_on_fd(EV_P_ int fd) {
|
||||
ipc_client *client = scalloc(1, sizeof(ipc_client));
|
||||
client->fd = fd;
|
||||
|
||||
client->read_callback = scalloc(1, sizeof(struct ev_io));
|
||||
client->read_callback = scalloc(1, sizeof(ev_io));
|
||||
client->read_callback->data = client;
|
||||
ev_io_init(client->read_callback, ipc_receive_message, fd, EV_READ);
|
||||
ev_io_start(EV_A_ client->read_callback);
|
||||
|
||||
client->write_callback = scalloc(1, sizeof(struct ev_io));
|
||||
client->write_callback = scalloc(1, sizeof(ev_io));
|
||||
client->write_callback->data = client;
|
||||
ev_io_init(client->write_callback, ipc_socket_writeable_cb, fd, EV_WRITE);
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ static bool parsing_window_rect;
|
||||
static bool parsing_geometry;
|
||||
static bool parsing_focus;
|
||||
static bool parsing_marks;
|
||||
struct Match *current_swallow;
|
||||
Match *current_swallow;
|
||||
static bool swallow_is_empty;
|
||||
static int num_marks;
|
||||
/* We need to save each container that needs to be marked if we want to support
|
||||
@ -302,7 +302,7 @@ static int json_string(void *ctx, const unsigned char *val, size_t len) {
|
||||
LOG("string: %.*s for key %s\n", (int)len, val, last_key);
|
||||
if (parsing_swallows) {
|
||||
char *sval;
|
||||
sasprintf(&sval, "%.*s", len, val);
|
||||
sasprintf(&sval, "%.*s", (int)len, val);
|
||||
if (strcasecmp(last_key, "class") == 0) {
|
||||
current_swallow->class = regex_new(sval);
|
||||
swallow_is_empty = false;
|
||||
|
||||
@ -229,7 +229,7 @@ void set_debug_logging(const bool _debug_logging) {
|
||||
* This is to be called by *LOG() which includes filename/linenumber/function.
|
||||
*
|
||||
*/
|
||||
static void vlog(const bool print, const char *fmt, va_list args) {
|
||||
__attribute__((format(printf, 2, 0))) static void vlog(const bool print, const char *fmt, va_list args) {
|
||||
/* Precisely one page to not consume too much memory but to hold enough
|
||||
* data to be useful. */
|
||||
static char message[4096];
|
||||
@ -396,7 +396,7 @@ char *current_log_stream_socket_path = NULL;
|
||||
* the list of log clients.
|
||||
*
|
||||
*/
|
||||
void log_new_client(EV_P_ struct ev_io *w, int revents) {
|
||||
void log_new_client(EV_P_ ev_io *w, int revents) {
|
||||
struct sockaddr_un peer;
|
||||
socklen_t len = sizeof(struct sockaddr_un);
|
||||
int fd;
|
||||
|
||||
52
src/main.c
52
src/main.c
@ -20,7 +20,6 @@
|
||||
#include <sys/resource.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
@ -47,7 +46,7 @@ int listen_fds;
|
||||
|
||||
/* We keep the xcb_prepare watcher around to be able to enable and disable it
|
||||
* temporarily for drag_pointer(). */
|
||||
static struct ev_prepare *xcb_prepare;
|
||||
static ev_prepare *xcb_prepare;
|
||||
|
||||
char **start_argv;
|
||||
|
||||
@ -117,7 +116,7 @@ I3_REST_ATOMS_XMACRO
|
||||
* 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) {
|
||||
static void xcb_got_event(EV_P_ ev_io *w, int revents) {
|
||||
/* empty, because xcb_prepare_cb are used */
|
||||
}
|
||||
|
||||
@ -146,8 +145,7 @@ static void xcb_prepare_cb(EV_P_ ev_prepare *w, int revents) {
|
||||
}
|
||||
|
||||
/* Strip off the highest bit (set if the event is generated) */
|
||||
int type = (event->response_type & 0x7F);
|
||||
|
||||
const int type = (event->response_type & 0x7F);
|
||||
handle_event(type, event);
|
||||
|
||||
free(event);
|
||||
@ -238,7 +236,7 @@ static void handle_term_signal(struct ev_loop *loop, ev_signal *signal, int reve
|
||||
*
|
||||
*/
|
||||
static void setup_term_handlers(void) {
|
||||
static struct ev_signal signal_watchers[6];
|
||||
static ev_signal signal_watchers[6];
|
||||
const size_t num_watchers = sizeof(signal_watchers) / sizeof(signal_watchers[0]);
|
||||
|
||||
/* We have to rely on libev functionality here and should not use
|
||||
@ -511,8 +509,7 @@ int main(int argc, char *argv[]) {
|
||||
err(EXIT_FAILURE, "Could not create socket");
|
||||
}
|
||||
|
||||
struct sockaddr_un addr;
|
||||
memset(&addr, 0, sizeof(struct sockaddr_un));
|
||||
struct sockaddr_un addr = {0};
|
||||
addr.sun_family = AF_LOCAL;
|
||||
strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
|
||||
FREE(socket_path);
|
||||
@ -539,7 +536,7 @@ int main(int argc, char *argv[]) {
|
||||
if (reply_type != I3_IPC_REPLY_TYPE_COMMAND) {
|
||||
errx(EXIT_FAILURE, "IPC: received reply of type %d but expected %d (COMMAND)", reply_type, I3_IPC_REPLY_TYPE_COMMAND);
|
||||
}
|
||||
printf("%.*s\n", reply_length, reply);
|
||||
printf("%.*s\n", reply_length, (char *)reply);
|
||||
FREE(reply);
|
||||
return 0;
|
||||
}
|
||||
@ -576,7 +573,7 @@ int main(int argc, char *argv[]) {
|
||||
#endif
|
||||
}
|
||||
|
||||
LOG("i3 %s starting\n", i3_version);
|
||||
LOG("i3 %s starting\n", _i3_version);
|
||||
|
||||
conn = xcb_connect(NULL, &conn_screen);
|
||||
if (xcb_connection_has_error(conn)) {
|
||||
@ -765,12 +762,12 @@ int main(int argc, char *argv[]) {
|
||||
xcb_set_selection_owner(conn, wm_sn_selection_owner, wm_sn, last_timestamp);
|
||||
|
||||
if (selection_reply && selection_reply->owner != XCB_NONE) {
|
||||
unsigned int usleep_time = 100000; /* 0.1 seconds */
|
||||
int check_rounds = 150; /* Wait for a maximum of 15 seconds */
|
||||
int check_rounds = 150; /* Wait for a maximum of 15 seconds */
|
||||
xcb_get_geometry_reply_t *geom_reply = NULL;
|
||||
|
||||
DLOG("waiting for old WM_Sn selection owner to exit");
|
||||
do {
|
||||
const unsigned int usleep_time = 100000;
|
||||
free(geom_reply);
|
||||
usleep(usleep_time);
|
||||
if (check_rounds-- == 0) {
|
||||
@ -791,8 +788,7 @@ int main(int argc, char *argv[]) {
|
||||
union {
|
||||
xcb_client_message_event_t message;
|
||||
char storage[32];
|
||||
} event;
|
||||
memset(&event, 0, sizeof(event));
|
||||
} event = {0};
|
||||
event.message.response_type = XCB_CLIENT_MESSAGE;
|
||||
event.message.window = root_screen->root;
|
||||
event.message.format = 32;
|
||||
@ -991,28 +987,28 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
scratchpad_fix_resolution();
|
||||
|
||||
xcb_query_pointer_reply_t *pointerreply;
|
||||
Output *output = NULL;
|
||||
if (!(pointerreply = xcb_query_pointer_reply(conn, pointercookie, NULL))) {
|
||||
xcb_query_pointer_reply_t *pointer_reply = xcb_query_pointer_reply(conn, pointercookie, NULL);
|
||||
if (!pointer_reply) {
|
||||
ELOG("Could not query pointer position, using first screen\n");
|
||||
} else {
|
||||
DLOG("Pointer at %d, %d\n", pointerreply->root_x, pointerreply->root_y);
|
||||
output = get_output_containing(pointerreply->root_x, pointerreply->root_y);
|
||||
DLOG("Pointer at %d, %d\n", pointer_reply->root_x, pointer_reply->root_y);
|
||||
output = get_output_containing(pointer_reply->root_x, pointer_reply->root_y);
|
||||
if (!output) {
|
||||
ELOG("ERROR: No screen at (%d, %d), starting on the first screen\n",
|
||||
pointerreply->root_x, pointerreply->root_y);
|
||||
pointer_reply->root_x, pointer_reply->root_y);
|
||||
}
|
||||
}
|
||||
if (!output) {
|
||||
output = get_first_output();
|
||||
}
|
||||
con_activate(con_descend_focused(output_get_content(output->con)));
|
||||
free(pointerreply);
|
||||
free(pointer_reply);
|
||||
|
||||
tree_render();
|
||||
|
||||
/* Listen to the IPC socket for clients */
|
||||
struct ev_io *ipc_io = scalloc(1, sizeof(struct ev_io));
|
||||
ev_io *ipc_io = scalloc(1, sizeof(struct ev_io));
|
||||
ev_io_init(ipc_io, ipc_new_client, ipc_socket, EV_READ);
|
||||
ev_io_start(main_loop, ipc_io);
|
||||
|
||||
@ -1020,11 +1016,11 @@ int main(int argc, char *argv[]) {
|
||||
char *log_stream_socket_path = get_process_filename("log-stream-socket");
|
||||
int log_socket = create_socket(log_stream_socket_path, ¤t_log_stream_socket_path);
|
||||
free(log_stream_socket_path);
|
||||
struct ev_io *log_io = NULL;
|
||||
ev_io *log_io = NULL;
|
||||
if (log_socket == -1) {
|
||||
ELOG("Could not create the log socket, i3-dump-log -f will not work\n");
|
||||
} else {
|
||||
log_io = scalloc(1, sizeof(struct ev_io));
|
||||
log_io = scalloc(1, sizeof(ev_io));
|
||||
ev_io_init(log_io, log_new_client, log_socket, EV_READ);
|
||||
ev_io_start(main_loop, log_io);
|
||||
}
|
||||
@ -1032,7 +1028,7 @@ int main(int argc, char *argv[]) {
|
||||
/* Also handle the UNIX domain sockets passed via socket
|
||||
* activation. The parameter 0 means "do not remove the
|
||||
* environment variables", we need to be able to reexec. */
|
||||
struct ev_io *socket_ipc_io = NULL;
|
||||
ev_io *socket_ipc_io = NULL;
|
||||
listen_fds = sd_listen_fds(0);
|
||||
if (listen_fds < 0) {
|
||||
ELOG("socket activation: Error in sd_listen_fds\n");
|
||||
@ -1053,7 +1049,7 @@ int main(int argc, char *argv[]) {
|
||||
ELOG("Could not disable FD_CLOEXEC on fd %d\n", fd);
|
||||
}
|
||||
|
||||
socket_ipc_io = scalloc(1, sizeof(struct ev_io));
|
||||
socket_ipc_io = scalloc(1, sizeof(ev_io));
|
||||
ev_io_init(socket_ipc_io, ipc_new_client, fd, EV_READ);
|
||||
ev_io_start(main_loop, socket_ipc_io);
|
||||
}
|
||||
@ -1076,8 +1072,8 @@ int main(int argc, char *argv[]) {
|
||||
/* Set the ewmh desktop properties. */
|
||||
ewmh_update_desktop_properties();
|
||||
|
||||
struct ev_io *xcb_watcher = scalloc(1, sizeof(struct ev_io));
|
||||
xcb_prepare = scalloc(1, sizeof(struct ev_prepare));
|
||||
ev_io *xcb_watcher = scalloc(1, sizeof(struct ev_io));
|
||||
xcb_prepare = scalloc(1, sizeof(ev_prepare));
|
||||
|
||||
ev_io_init(xcb_watcher, xcb_got_event, xcb_get_file_descriptor(conn), EV_READ);
|
||||
ev_io_start(main_loop, xcb_watcher);
|
||||
@ -1111,7 +1107,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
/* Strip off the highest bit (set if the event is generated) */
|
||||
int type = (event->response_type & 0x7F);
|
||||
const int type = (event->response_type & 0x7F);
|
||||
|
||||
/* We still need to handle MapRequests which are sent in the
|
||||
* timespan starting from when we register as a window manager and
|
||||
|
||||
13
src/manage.c
13
src/manage.c
@ -43,26 +43,23 @@ static void _remove_matches(Con *con) {
|
||||
*/
|
||||
void manage_existing_windows(xcb_window_t root) {
|
||||
xcb_query_tree_reply_t *reply;
|
||||
int i, len;
|
||||
xcb_window_t *children;
|
||||
xcb_get_window_attributes_cookie_t *cookies;
|
||||
|
||||
/* Get the tree of windows whose parent is the root window (= all) */
|
||||
if ((reply = xcb_query_tree_reply(conn, xcb_query_tree(conn, root), 0)) == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
len = xcb_query_tree_children_length(reply);
|
||||
cookies = smalloc(len * sizeof(*cookies));
|
||||
int len = xcb_query_tree_children_length(reply);
|
||||
xcb_get_window_attributes_cookie_t *cookies = smalloc(len * sizeof(*cookies));
|
||||
|
||||
/* Request the window attributes for every window */
|
||||
children = xcb_query_tree_children(reply);
|
||||
for (i = 0; i < len; ++i) {
|
||||
xcb_window_t *children = xcb_query_tree_children(reply);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
cookies[i] = xcb_get_window_attributes(conn, children[i]);
|
||||
}
|
||||
|
||||
/* Call manage_window with the attributes for every window */
|
||||
for (i = 0; i < len; ++i) {
|
||||
for (int i = 0; i < len; ++i) {
|
||||
manage_window(children[i], cookies[i], true);
|
||||
}
|
||||
|
||||
|
||||
19
src/output.c
19
src/output.c
@ -33,13 +33,17 @@ Con *output_get_content(Con *output) {
|
||||
Output *get_output_from_string(Output *current_output, const char *output_str) {
|
||||
if (strcasecmp(output_str, "current") == 0) {
|
||||
return get_output_for_con(focused);
|
||||
} else if (strcasecmp(output_str, "left") == 0) {
|
||||
}
|
||||
if (strcasecmp(output_str, "left") == 0) {
|
||||
return get_output_next_wrap(D_LEFT, current_output);
|
||||
} else if (strcasecmp(output_str, "right") == 0) {
|
||||
}
|
||||
if (strcasecmp(output_str, "right") == 0) {
|
||||
return get_output_next_wrap(D_RIGHT, current_output);
|
||||
} else if (strcasecmp(output_str, "up") == 0) {
|
||||
}
|
||||
if (strcasecmp(output_str, "up") == 0) {
|
||||
return get_output_next_wrap(D_UP, current_output);
|
||||
} else if (strcasecmp(output_str, "down") == 0) {
|
||||
}
|
||||
if (strcasecmp(output_str, "down") == 0) {
|
||||
return get_output_next_wrap(D_DOWN, current_output);
|
||||
}
|
||||
|
||||
@ -83,13 +87,13 @@ Output *get_output_for_con(Con *con) {
|
||||
void output_push_sticky_windows(Con *old_focus) {
|
||||
Con *output;
|
||||
TAILQ_FOREACH (output, &(croot->focus_head), focused) {
|
||||
Con *workspace, *visible_ws = NULL;
|
||||
Con *visible_ws = NULL;
|
||||
GREP_FIRST(visible_ws, output_get_content(output), workspace_is_visible(child));
|
||||
|
||||
/* We use this loop instead of TAILQ_FOREACH to avoid problems if the
|
||||
* sticky window was the last window on that workspace as moving it in
|
||||
* this case will close the workspace. */
|
||||
for (workspace = TAILQ_FIRST(&(output_get_content(output)->focus_head));
|
||||
for (Con *workspace = TAILQ_FIRST(&(output_get_content(output)->focus_head));
|
||||
workspace != TAILQ_END(&(output_get_content(output)->focus_head));) {
|
||||
Con *current_ws = workspace;
|
||||
workspace = TAILQ_NEXT(workspace, focused);
|
||||
@ -97,8 +101,7 @@ void output_push_sticky_windows(Con *old_focus) {
|
||||
/* Since moving the windows actually removes them from the list of
|
||||
* floating windows on this workspace, here too we need to use
|
||||
* another loop than TAILQ_FOREACH. */
|
||||
Con *child;
|
||||
for (child = TAILQ_FIRST(&(current_ws->focus_head));
|
||||
for (Con *child = TAILQ_FIRST(&(current_ws->focus_head));
|
||||
child != TAILQ_END(&(current_ws->focus_head));) {
|
||||
Con *current = child;
|
||||
child = TAILQ_NEXT(child, focused);
|
||||
|
||||
72
src/randr.c
72
src/randr.c
@ -182,24 +182,28 @@ Output *get_output_with_dimensions(Rect rect) {
|
||||
*/
|
||||
Output *output_containing_rect(Rect rect) {
|
||||
Output *output;
|
||||
int lx = rect.x, uy = rect.y;
|
||||
int rx = rect.x + rect.width, by = rect.y + rect.height;
|
||||
long max_area = 0;
|
||||
const int lx = rect.x;
|
||||
const int uy = rect.y;
|
||||
const int rx = rect.x + rect.width;
|
||||
const int by = rect.y + rect.height;
|
||||
Output *result = NULL;
|
||||
TAILQ_FOREACH (output, &outputs, outputs) {
|
||||
if (!output->active) {
|
||||
continue;
|
||||
}
|
||||
int lx_o = (int)output->rect.x, uy_o = (int)output->rect.y;
|
||||
int rx_o = (int)(output->rect.x + output->rect.width), by_o = (int)(output->rect.y + output->rect.height);
|
||||
const int lx_o = (int)output->rect.x;
|
||||
const int uy_o = (int)output->rect.y;
|
||||
const int rx_o = (int)(output->rect.x + output->rect.width);
|
||||
const int by_o = (int)(output->rect.y + output->rect.height);
|
||||
DLOG("comparing x=%d y=%d with x=%d and y=%d width %d height %d\n",
|
||||
rect.x, rect.y, output->rect.x, output->rect.y, output->rect.width, output->rect.height);
|
||||
int left = max(lx, lx_o);
|
||||
int right = min(rx, rx_o);
|
||||
int bottom = min(by, by_o);
|
||||
int top = max(uy, uy_o);
|
||||
const int left = max(lx, lx_o);
|
||||
const int right = min(rx, rx_o);
|
||||
const int bottom = min(by, by_o);
|
||||
const int top = max(uy, uy_o);
|
||||
if (left < right && bottom > top) {
|
||||
long area = (right - left) * (bottom - top);
|
||||
const long max_area = 0;
|
||||
const long area = (right - left) * (bottom - top);
|
||||
if (area > max_area) {
|
||||
result = output;
|
||||
}
|
||||
@ -252,18 +256,15 @@ Output *get_output_next_wrap(direction_t direction, Output *current) {
|
||||
* specified (note that “current” counts as such an output).
|
||||
*
|
||||
*/
|
||||
Output *get_output_next(direction_t direction, Output *current, output_close_far_t close_far) {
|
||||
Rect *cur = &(current->rect),
|
||||
*other;
|
||||
Output *output,
|
||||
*best = NULL;
|
||||
Output *get_output_next(const direction_t direction, Output *current, output_close_far_t close_far) {
|
||||
const Rect *cur = &(current->rect);
|
||||
Output *output, *best = NULL;
|
||||
TAILQ_FOREACH (output, &outputs, outputs) {
|
||||
if (!output->active) {
|
||||
continue;
|
||||
}
|
||||
|
||||
other = &(output->rect);
|
||||
|
||||
const Rect *other = &(output->rect);
|
||||
if ((direction == D_RIGHT && other->x > cur->x) ||
|
||||
(direction == D_LEFT && other->x < cur->x)) {
|
||||
/* Skip the output when it doesn’t overlap the other one’s y
|
||||
@ -539,10 +540,10 @@ static void output_change_mode(xcb_connection_t *conn, Output *output) {
|
||||
assert(output->con != NULL);
|
||||
output->con->rect = output->rect;
|
||||
|
||||
Con *content, *workspace, *child;
|
||||
Con *workspace, *child;
|
||||
|
||||
/* Point content to the container of the workspaces */
|
||||
content = output_get_content(output->con);
|
||||
const Con *content = output_get_content(output->con);
|
||||
|
||||
/* Fix the position of all floating windows on this output.
|
||||
* The 'rect' of each workspace will be updated in src/render.c. */
|
||||
@ -803,10 +804,8 @@ static void randr_query_outputs_14(void) {
|
||||
DLOG("Querying outputs using RandR ≤ 1.4\n");
|
||||
|
||||
/* Get screen resources (primary output, crtcs, outputs, modes) */
|
||||
xcb_randr_get_screen_resources_current_cookie_t rcookie;
|
||||
rcookie = xcb_randr_get_screen_resources_current(conn, root);
|
||||
xcb_randr_get_output_primary_cookie_t pcookie;
|
||||
pcookie = xcb_randr_get_output_primary(conn, root);
|
||||
const xcb_randr_get_screen_resources_current_cookie_t rcookie = xcb_randr_get_screen_resources_current(conn, root);
|
||||
const xcb_randr_get_output_primary_cookie_t pcookie = xcb_randr_get_output_primary(conn, root);
|
||||
|
||||
if ((primary = xcb_randr_get_output_primary_reply(conn, pcookie, NULL)) == NULL) {
|
||||
ELOG("Could not get RandR primary output\n");
|
||||
@ -868,10 +867,9 @@ static void move_content(Con *con) {
|
||||
|
||||
/* 2: iterate through workspaces and re-assign them, fixing the coordinates
|
||||
* of floating containers as we go */
|
||||
Con *current;
|
||||
Con *old_content = output_get_content(con);
|
||||
const Con *old_content = output_get_content(con);
|
||||
while (!TAILQ_EMPTY(&(old_content->nodes_head))) {
|
||||
current = TAILQ_FIRST(&(old_content->nodes_head));
|
||||
Con *current = TAILQ_FIRST(&(old_content->nodes_head));
|
||||
if (current != next && TAILQ_EMPTY(&(current->focus_head))) {
|
||||
/* the workspace is empty and not focused, get rid of it */
|
||||
DLOG("Getting rid of current = %p / %s (empty, unfocused)\n", current, current->name);
|
||||
@ -903,12 +901,10 @@ static void move_content(Con *con) {
|
||||
continue;
|
||||
}
|
||||
DLOG("Handling dock con %p\n", child);
|
||||
Con *dock;
|
||||
while (!TAILQ_EMPTY(&(child->nodes_head))) {
|
||||
dock = TAILQ_FIRST(&(child->nodes_head));
|
||||
Con *nc;
|
||||
Match *match;
|
||||
nc = con_for_window(first, dock->window, &match);
|
||||
Con *dock = TAILQ_FIRST(&(child->nodes_head));
|
||||
Con *nc = con_for_window(first, dock->window, &match);
|
||||
DLOG("Moving dock client %p to nc %p\n", dock, nc);
|
||||
con_detach(dock);
|
||||
DLOG("Re-attaching\n");
|
||||
@ -928,8 +924,6 @@ static void move_content(Con *con) {
|
||||
*
|
||||
*/
|
||||
void randr_query_outputs(void) {
|
||||
Output *output, *other;
|
||||
|
||||
if (!randr_query_outputs_15()) {
|
||||
randr_query_outputs_14();
|
||||
}
|
||||
@ -947,6 +941,7 @@ void randr_query_outputs(void) {
|
||||
|
||||
/* Check for clones, disable the clones and reduce the mode to the
|
||||
* lowest common mode */
|
||||
Output *output;
|
||||
TAILQ_FOREACH (output, &outputs, outputs) {
|
||||
if (!output->active || output->to_be_disabled) {
|
||||
continue;
|
||||
@ -954,7 +949,7 @@ void randr_query_outputs(void) {
|
||||
DLOG("output %p / %s, position (%d, %d), checking for clones\n",
|
||||
output, output_primary_name(output), output->rect.x, output->rect.y);
|
||||
|
||||
for (other = output;
|
||||
for (Output *other = output;
|
||||
other != TAILQ_END(&outputs);
|
||||
other = TAILQ_NEXT(other, outputs)) {
|
||||
if (other == output || !other->active || other->to_be_disabled) {
|
||||
@ -1006,8 +1001,7 @@ void randr_query_outputs(void) {
|
||||
* those mentioned #3767 e.g. when a CT_OUTPUT is created from an in-place
|
||||
* restart's layout but the output is disabled by a randr query happening
|
||||
* at the same time. */
|
||||
Con *con;
|
||||
for (con = TAILQ_FIRST(&(croot->nodes_head)); con;) {
|
||||
for (Con *con = TAILQ_FIRST(&(croot->nodes_head)); con;) {
|
||||
Con *next = TAILQ_NEXT(con, nodes);
|
||||
if (!con_is_internal(con) && get_output_by_name(con->name, true) == NULL) {
|
||||
DLOG("No output %s found, moving its old content to first output\n", con->name);
|
||||
@ -1094,13 +1088,11 @@ static void fallback_to_root_output(void) {
|
||||
*
|
||||
*/
|
||||
void randr_init(int *event_base, const bool disable_randr15) {
|
||||
const xcb_query_extension_reply_t *extreply;
|
||||
|
||||
root_output = create_root_output(conn);
|
||||
TAILQ_INSERT_TAIL(&outputs, root_output, outputs);
|
||||
|
||||
extreply = xcb_get_extension_data(conn, &xcb_randr_id);
|
||||
if (!extreply->present) {
|
||||
const xcb_query_extension_reply_t *extension_reply = xcb_get_extension_data(conn, &xcb_randr_id);
|
||||
if (!extension_reply->present) {
|
||||
DLOG("RandR is not present, activating root output.\n");
|
||||
fallback_to_root_output();
|
||||
return;
|
||||
@ -1126,7 +1118,7 @@ void randr_init(int *event_base, const bool disable_randr15) {
|
||||
randr_query_outputs();
|
||||
|
||||
if (event_base != NULL) {
|
||||
*event_base = extreply->first_event;
|
||||
*event_base = extension_reply->first_event;
|
||||
}
|
||||
|
||||
xcb_randr_select_input(conn, root,
|
||||
|
||||
@ -59,15 +59,12 @@ void regex_free(struct regex *regex) {
|
||||
* be visible without debug logging.
|
||||
*
|
||||
*/
|
||||
bool regex_matches(struct regex *regex, const char *input) {
|
||||
pcre2_match_data *match_data;
|
||||
int rc;
|
||||
|
||||
match_data = pcre2_match_data_create_from_pattern(regex->regex, NULL);
|
||||
bool regex_matches(const struct regex *regex, const char *input) {
|
||||
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(regex->regex, NULL);
|
||||
|
||||
/* We use strlen() because pcre_exec() expects the length of the input
|
||||
* string in bytes */
|
||||
rc = pcre2_match(regex->regex, (PCRE2_SPTR)input, strlen(input), 0, 0, match_data, NULL);
|
||||
const int rc = pcre2_match(regex->regex, (PCRE2_SPTR)input, strlen(input), 0, 0, match_data, NULL);
|
||||
pcre2_match_data_free(match_data);
|
||||
if (rc > 0) {
|
||||
LOG("Regular expression \"%s\" matches \"%s\"\n",
|
||||
|
||||
@ -85,7 +85,6 @@ void render_con(Con *con) {
|
||||
params.y = con->rect.y;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
con->mapped = true;
|
||||
|
||||
/* if this container contains a window, set the coordinates */
|
||||
@ -159,6 +158,7 @@ void render_con(Con *con) {
|
||||
} else if (con->type == CT_ROOT) {
|
||||
render_root(con, fullscreen);
|
||||
} else {
|
||||
int i = 0;
|
||||
Con *child;
|
||||
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
|
||||
assert(params.children > 0);
|
||||
@ -231,9 +231,9 @@ static int *precalculate_sizes(Con *con, render_params *p) {
|
||||
|
||||
Con *child;
|
||||
int i = 0, assigned = 0;
|
||||
int total = con_rect_size_in_orientation(con);
|
||||
const int total = con_rect_size_in_orientation(con);
|
||||
TAILQ_FOREACH (child, &(con->nodes_head), nodes) {
|
||||
double percentage = child->percent > 0.0 ? child->percent : 1.0 / p->children;
|
||||
const double percentage = child->percent > 0.0 ? child->percent : 1.0 / p->children;
|
||||
assigned += sizes[i++] = lround(percentage * total);
|
||||
}
|
||||
assert(assigned == total ||
|
||||
|
||||
@ -37,13 +37,13 @@ static TAILQ_HEAD(state_head, placeholder_state) state_head =
|
||||
|
||||
static xcb_connection_t *restore_conn;
|
||||
|
||||
static struct ev_io *xcb_watcher;
|
||||
static struct ev_prepare *xcb_prepare;
|
||||
static ev_io *xcb_watcher;
|
||||
static ev_prepare *xcb_prepare;
|
||||
|
||||
static void restore_handle_event(int type, xcb_generic_event_t *event);
|
||||
|
||||
/* Documentation for these functions can be found in src/main.c, starting at xcb_got_event */
|
||||
static void restore_xcb_got_event(EV_P_ struct ev_io *w, int revents) {
|
||||
static void restore_xcb_got_event(EV_P_ ev_io *w, int revents) {
|
||||
}
|
||||
|
||||
static void restore_xcb_prepare_cb(EV_P_ ev_prepare *w, int revents) {
|
||||
@ -89,9 +89,8 @@ void restore_connect(void) {
|
||||
ev_io_stop(main_loop, xcb_watcher);
|
||||
ev_prepare_stop(main_loop, xcb_prepare);
|
||||
|
||||
placeholder_state *state;
|
||||
while (!TAILQ_EMPTY(&state_head)) {
|
||||
state = TAILQ_FIRST(&state_head);
|
||||
placeholder_state *state = TAILQ_FIRST(&state_head);
|
||||
TAILQ_REMOVE(&state_head, state, state);
|
||||
free(state);
|
||||
}
|
||||
@ -117,8 +116,8 @@ void restore_connect(void) {
|
||||
errx(EXIT_FAILURE, "Cannot open display");
|
||||
}
|
||||
|
||||
xcb_watcher = scalloc(1, sizeof(struct ev_io));
|
||||
xcb_prepare = scalloc(1, sizeof(struct ev_prepare));
|
||||
xcb_watcher = scalloc(1, sizeof(ev_io));
|
||||
xcb_prepare = scalloc(1, sizeof(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);
|
||||
|
||||
@ -21,8 +21,7 @@ void scratchpad_move(Con *con) {
|
||||
LOG("'move scratchpad' used on a workspace \"%s\". Calling it "
|
||||
"recursively on all windows on this workspace.\n",
|
||||
con->name);
|
||||
Con *current;
|
||||
current = TAILQ_FIRST(&(con->focus_head));
|
||||
Con *current = TAILQ_FIRST(&(con->focus_head));
|
||||
while (current) {
|
||||
Con *next = TAILQ_NEXT(current, focused);
|
||||
scratchpad_move(current);
|
||||
|
||||
@ -44,8 +44,8 @@
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int sd_listen_fds(int unset_environment) {
|
||||
int r, fd;
|
||||
int sd_listen_fds(const int unset_environment) {
|
||||
int r;
|
||||
const char *e;
|
||||
char *p = NULL;
|
||||
unsigned long l;
|
||||
@ -92,7 +92,7 @@ int sd_listen_fds(int unset_environment) {
|
||||
goto finish;
|
||||
}
|
||||
|
||||
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int)l; fd++) {
|
||||
for (int fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int)l; fd++) {
|
||||
int flags;
|
||||
|
||||
if ((flags = fcntl(fd, F_GETFD)) < 0) {
|
||||
@ -138,9 +138,8 @@ int sd_is_fifo(int fd, const char *path) {
|
||||
}
|
||||
|
||||
if (path) {
|
||||
struct stat st_path;
|
||||
struct stat st_path = {0};
|
||||
|
||||
memset(&st_path, 0, sizeof(st_path));
|
||||
if (stat(path, &st_path) < 0) {
|
||||
if (errno == ENOENT || errno == ENOTDIR) {
|
||||
return 0;
|
||||
@ -434,10 +433,9 @@ int sd_notifyf(int unset_environment, const char *format, ...) {
|
||||
#else
|
||||
va_list ap;
|
||||
char *p = NULL;
|
||||
int r;
|
||||
|
||||
va_start(ap, format);
|
||||
r = vasprintf(&p, format, ap);
|
||||
int r = vasprintf(&p, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
if (r < 0 || !p) {
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
|
||||
*
|
||||
* startup.c: Startup notification code. Ensures a startup notification context
|
||||
* is setup when launching applications. We store the current
|
||||
* is set up when launching applications. We store the current
|
||||
* workspace to open windows in that startup notification context on
|
||||
* the appropriate workspace.
|
||||
*
|
||||
@ -71,15 +71,14 @@ static void startup_timeout(EV_P_ ev_timer *w, int revents) {
|
||||
*
|
||||
*/
|
||||
static int _prune_startup_sequences(void) {
|
||||
time_t current_time = time(NULL);
|
||||
const time_t current_time = time(NULL);
|
||||
int active_sequences = 0;
|
||||
|
||||
/* Traverse the list and delete everything which was marked for deletion 30
|
||||
* seconds ago or earlier. */
|
||||
struct Startup_Sequence *current, *next;
|
||||
for (next = TAILQ_FIRST(&startup_sequences);
|
||||
for (struct Startup_Sequence *next = TAILQ_FIRST(&startup_sequences);
|
||||
next != TAILQ_END(&startup_sequences);) {
|
||||
current = next;
|
||||
struct Startup_Sequence *current = next;
|
||||
next = TAILQ_NEXT(next, sequences);
|
||||
|
||||
if (current->delete_at == 0) {
|
||||
@ -151,7 +150,7 @@ void start_application(const char *command, bool no_startup_id) {
|
||||
free(first_word);
|
||||
|
||||
/* Trigger a timeout after 60 seconds */
|
||||
struct ev_timer *timeout = scalloc(1, sizeof(struct ev_timer));
|
||||
ev_timer *timeout = scalloc(1, sizeof(struct ev_timer));
|
||||
ev_timer_init(timeout, startup_timeout, 60.0, 0.);
|
||||
timeout->data = context;
|
||||
ev_timer_start(main_loop, timeout);
|
||||
@ -210,12 +209,10 @@ void start_application(const char *command, bool no_startup_id) {
|
||||
*
|
||||
*/
|
||||
void startup_monitor_event(SnMonitorEvent *event, void *userdata) {
|
||||
SnStartupSequence *snsequence;
|
||||
|
||||
snsequence = sn_monitor_event_get_startup_sequence(event);
|
||||
SnStartupSequence *sn_startup_sequence = sn_monitor_event_get_startup_sequence(event);
|
||||
|
||||
/* Get the corresponding internal startup sequence */
|
||||
const char *id = sn_startup_sequence_get_id(snsequence);
|
||||
const char *id = sn_startup_sequence_get_id(sn_startup_sequence);
|
||||
struct Startup_Sequence *current, *sequence = NULL;
|
||||
TAILQ_FOREACH (current, &startup_sequences, sequences) {
|
||||
if (strcmp(current->id, id) != 0) {
|
||||
@ -233,7 +230,7 @@ void startup_monitor_event(SnMonitorEvent *event, void *userdata) {
|
||||
|
||||
switch (sn_monitor_event_get_type(event)) {
|
||||
case SN_MONITOR_EVENT_COMPLETED:
|
||||
DLOG("startup sequence %s completed\n", sn_startup_sequence_get_id(snsequence));
|
||||
DLOG("startup sequence %s completed\n", sn_startup_sequence_get_id(sn_startup_sequence));
|
||||
|
||||
/* Mark the given sequence for deletion in 30 seconds. */
|
||||
time_t current_time = time(NULL);
|
||||
@ -274,7 +271,7 @@ void startup_sequence_rename_workspace(const char *old_name, const char *new_nam
|
||||
* Gets the stored startup sequence for the _NET_STARTUP_ID of a given window.
|
||||
*
|
||||
*/
|
||||
struct Startup_Sequence *startup_sequence_get(i3Window *cwindow,
|
||||
struct Startup_Sequence *startup_sequence_get(const i3Window *cwindow,
|
||||
xcb_get_property_reply_t *startup_id_reply, bool ignore_mapped_leader) {
|
||||
/* The _NET_STARTUP_ID is only needed during this function, so we get it
|
||||
* here and don’t save it in the 'cwindow'. */
|
||||
@ -299,10 +296,8 @@ struct Startup_Sequence *startup_sequence_get(i3Window *cwindow,
|
||||
|
||||
DLOG("Checking leader window 0x%08x\n", cwindow->leader);
|
||||
|
||||
xcb_get_property_cookie_t cookie;
|
||||
|
||||
cookie = xcb_get_property(conn, false, cwindow->leader,
|
||||
A__NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
|
||||
const xcb_get_property_cookie_t cookie = xcb_get_property(conn, false, cwindow->leader,
|
||||
A__NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
|
||||
startup_id_reply = xcb_get_property_reply(conn, cookie, NULL);
|
||||
|
||||
if (startup_id_reply == NULL ||
|
||||
@ -348,7 +343,7 @@ struct Startup_Sequence *startup_sequence_get(i3Window *cwindow,
|
||||
* Returns NULL otherwise.
|
||||
*
|
||||
*/
|
||||
char *startup_workspace_for_window(i3Window *cwindow, xcb_get_property_reply_t *startup_id_reply) {
|
||||
char *startup_workspace_for_window(const i3Window *cwindow, xcb_get_property_reply_t *startup_id_reply) {
|
||||
struct Startup_Sequence *sequence = startup_sequence_get(cwindow, startup_id_reply, false);
|
||||
if (sequence == NULL) {
|
||||
return NULL;
|
||||
@ -369,16 +364,12 @@ char *startup_workspace_for_window(i3Window *cwindow, xcb_get_property_reply_t *
|
||||
* Deletes the startup sequence for a window if it exists.
|
||||
*
|
||||
*/
|
||||
void startup_sequence_delete_by_window(i3Window *win) {
|
||||
struct Startup_Sequence *sequence;
|
||||
xcb_get_property_cookie_t cookie;
|
||||
xcb_get_property_reply_t *startup_id_reply;
|
||||
void startup_sequence_delete_by_window(const i3Window *win) {
|
||||
const xcb_get_property_cookie_t cookie = xcb_get_property(conn, false, win->id, A__NET_STARTUP_ID,
|
||||
XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
|
||||
xcb_get_property_reply_t *startup_id_reply = xcb_get_property_reply(conn, cookie, NULL);
|
||||
|
||||
cookie = xcb_get_property(conn, false, win->id, A__NET_STARTUP_ID,
|
||||
XCB_GET_PROPERTY_TYPE_ANY, 0, 512);
|
||||
startup_id_reply = xcb_get_property_reply(conn, cookie, NULL);
|
||||
|
||||
sequence = startup_sequence_get(win, startup_id_reply, true);
|
||||
struct Startup_Sequence *sequence = startup_sequence_get(win, startup_id_reply, true);
|
||||
if (sequence != NULL) {
|
||||
startup_sequence_delete(sequence);
|
||||
}
|
||||
|
||||
79
src/tree.c
79
src/tree.c
@ -9,8 +9,8 @@
|
||||
*/
|
||||
#include "all.h"
|
||||
|
||||
struct Con *croot;
|
||||
struct Con *focused;
|
||||
Con *croot;
|
||||
Con *focused;
|
||||
|
||||
struct all_cons_head all_cons = TAILQ_HEAD_INITIALIZER(all_cons);
|
||||
|
||||
@ -200,17 +200,16 @@ bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_par
|
||||
}
|
||||
|
||||
DLOG("closing %p, kill_window = %d\n", con, kill_window);
|
||||
Con *child, *nextchild;
|
||||
bool abort_kill = false;
|
||||
/* We cannot use TAILQ_FOREACH because the children get deleted
|
||||
* in their parent’s nodes_head */
|
||||
for (child = TAILQ_FIRST(&(con->nodes_head)); child;) {
|
||||
nextchild = TAILQ_NEXT(child, nodes);
|
||||
for (Con *child = TAILQ_FIRST(&(con->nodes_head)); child;) {
|
||||
Con *next_child = TAILQ_NEXT(child, nodes);
|
||||
DLOG("killing child=%p\n", child);
|
||||
if (!tree_close_internal(child, kill_window, true)) {
|
||||
abort_kill = true;
|
||||
}
|
||||
child = nextchild;
|
||||
child = next_child;
|
||||
}
|
||||
|
||||
if (abort_kill) {
|
||||
@ -222,42 +221,40 @@ bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_par
|
||||
if (kill_window != DONT_KILL_WINDOW) {
|
||||
x_window_kill(con->window->id, kill_window);
|
||||
return false;
|
||||
} else {
|
||||
xcb_void_cookie_t cookie;
|
||||
/* Ignore any further events by clearing the event mask,
|
||||
* unmap the window,
|
||||
* then reparent it to the root window. */
|
||||
xcb_change_window_attributes(conn, con->window->id,
|
||||
XCB_CW_EVENT_MASK, (uint32_t[]){XCB_NONE});
|
||||
xcb_unmap_window(conn, con->window->id);
|
||||
cookie = xcb_reparent_window(conn, con->window->id, root, con->rect.x, con->rect.y);
|
||||
|
||||
/* Ignore X11 errors for the ReparentWindow request.
|
||||
* X11 Errors are returned when the window was already destroyed */
|
||||
add_ignore_event(cookie.sequence, 0);
|
||||
|
||||
/* We are no longer handling this window, thus set WM_STATE to
|
||||
* WM_STATE_WITHDRAWN (see ICCCM 4.1.3.1) */
|
||||
long data[] = {XCB_ICCCM_WM_STATE_WITHDRAWN, XCB_NONE};
|
||||
cookie = xcb_change_property(conn, XCB_PROP_MODE_REPLACE,
|
||||
con->window->id, A_WM_STATE, A_WM_STATE, 32, 2, data);
|
||||
|
||||
/* Remove the window from the save set. All windows in the save set
|
||||
* will be mapped when i3 closes its connection (e.g. when
|
||||
* restarting). This is not what we want, since some apps keep
|
||||
* unmapped windows around and don’t expect them to suddenly be
|
||||
* mapped. See https://bugs.i3wm.org/1617 */
|
||||
xcb_change_save_set(conn, XCB_SET_MODE_DELETE, con->window->id);
|
||||
|
||||
/* Stop receiving ShapeNotify events. */
|
||||
if (shape_supported) {
|
||||
xcb_shape_select_input(conn, con->window->id, false);
|
||||
}
|
||||
|
||||
/* Ignore X11 errors for the ReparentWindow request.
|
||||
* X11 Errors are returned when the window was already destroyed */
|
||||
add_ignore_event(cookie.sequence, 0);
|
||||
}
|
||||
/* Ignore any further events by clearing the event mask,
|
||||
* unmap the window,
|
||||
* then reparent it to the root window. */
|
||||
xcb_change_window_attributes(conn, con->window->id,
|
||||
XCB_CW_EVENT_MASK, (uint32_t[]){XCB_NONE});
|
||||
xcb_unmap_window(conn, con->window->id);
|
||||
xcb_void_cookie_t cookie = xcb_reparent_window(conn, con->window->id, root, con->rect.x, con->rect.y);
|
||||
|
||||
/* Ignore X11 errors for the ReparentWindow request.
|
||||
* X11 Errors are returned when the window was already destroyed */
|
||||
add_ignore_event(cookie.sequence, 0);
|
||||
|
||||
/* We are no longer handling this window, thus set WM_STATE to
|
||||
* WM_STATE_WITHDRAWN (see ICCCM 4.1.3.1) */
|
||||
long data[] = {XCB_ICCCM_WM_STATE_WITHDRAWN, XCB_NONE};
|
||||
cookie = xcb_change_property(conn, XCB_PROP_MODE_REPLACE,
|
||||
con->window->id, A_WM_STATE, A_WM_STATE, 32, 2, data);
|
||||
|
||||
/* Remove the window from the save set. All windows in the save set
|
||||
* will be mapped when i3 closes its connection (e.g. when
|
||||
* restarting). This is not what we want, since some apps keep
|
||||
* unmapped windows around and don’t expect them to suddenly be
|
||||
* mapped. See https://bugs.i3wm.org/1617 */
|
||||
xcb_change_save_set(conn, XCB_SET_MODE_DELETE, con->window->id);
|
||||
|
||||
/* Stop receiving ShapeNotify events. */
|
||||
if (shape_supported) {
|
||||
xcb_shape_select_input(conn, con->window->id, false);
|
||||
}
|
||||
|
||||
/* Ignore X11 errors for the ReparentWindow request.
|
||||
* X11 Errors are returned when the window was already destroyed */
|
||||
add_ignore_event(cookie.sequence, 0);
|
||||
ipc_send_window_event("close", con);
|
||||
window_free(con->window);
|
||||
con->window = NULL;
|
||||
|
||||
28
src/util.c
28
src/util.c
@ -21,42 +21,42 @@
|
||||
#include <sys/cdefs.h>
|
||||
#endif
|
||||
|
||||
int min(int a, int b) {
|
||||
__attribute__((__const__)) int min(const int a, const int b) {
|
||||
return (a < b ? a : b);
|
||||
}
|
||||
|
||||
int max(int a, int b) {
|
||||
__attribute__((__const__)) int max(const int a, const int b) {
|
||||
return (a > b ? a : b);
|
||||
}
|
||||
|
||||
bool rect_contains(Rect rect, uint32_t x, uint32_t y) {
|
||||
__attribute__((__const__)) bool rect_contains(const Rect rect, const uint32_t x, const uint32_t y) {
|
||||
return (x >= rect.x &&
|
||||
x <= (rect.x + rect.width) &&
|
||||
y >= rect.y &&
|
||||
y <= (rect.y + rect.height));
|
||||
}
|
||||
|
||||
Rect rect_add(Rect a, Rect b) {
|
||||
__attribute__((__const__)) Rect rect_add(const Rect a, const Rect b) {
|
||||
return (Rect){a.x + b.x,
|
||||
a.y + b.y,
|
||||
a.width + b.width,
|
||||
a.height + b.height};
|
||||
}
|
||||
|
||||
Rect rect_sub(Rect a, Rect b) {
|
||||
__attribute__((__const__)) Rect rect_sub(const Rect a, const Rect b) {
|
||||
return (Rect){a.x - b.x,
|
||||
a.y - b.y,
|
||||
a.width - b.width,
|
||||
a.height - b.height};
|
||||
}
|
||||
|
||||
Rect rect_sanitize_dimensions(Rect rect) {
|
||||
__attribute__((__const__)) Rect rect_sanitize_dimensions(Rect rect) {
|
||||
rect.width = (int32_t)rect.width <= 0 ? 1 : rect.width;
|
||||
rect.height = (int32_t)rect.height <= 0 ? 1 : rect.height;
|
||||
return rect;
|
||||
}
|
||||
|
||||
bool rect_equals(Rect a, Rect b) {
|
||||
__attribute__((__const__)) bool rect_equals(const Rect a, const Rect b) {
|
||||
return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height;
|
||||
}
|
||||
|
||||
@ -85,17 +85,21 @@ bool layout_from_name(const char *layout_str, layout_t *out) {
|
||||
if (strcmp(layout_str, "default") == 0) {
|
||||
*out = L_DEFAULT;
|
||||
return true;
|
||||
} else if (strcasecmp(layout_str, "stacked") == 0 ||
|
||||
strcasecmp(layout_str, "stacking") == 0) {
|
||||
}
|
||||
if (strcasecmp(layout_str, "stacked") == 0 ||
|
||||
strcasecmp(layout_str, "stacking") == 0) {
|
||||
*out = L_STACKED;
|
||||
return true;
|
||||
} else if (strcasecmp(layout_str, "tabbed") == 0) {
|
||||
}
|
||||
if (strcasecmp(layout_str, "tabbed") == 0) {
|
||||
*out = L_TABBED;
|
||||
return true;
|
||||
} else if (strcasecmp(layout_str, "splitv") == 0) {
|
||||
}
|
||||
if (strcasecmp(layout_str, "splitv") == 0) {
|
||||
*out = L_SPLITV;
|
||||
return true;
|
||||
} else if (strcasecmp(layout_str, "splith") == 0) {
|
||||
}
|
||||
if (strcasecmp(layout_str, "splith") == 0) {
|
||||
*out = L_SPLITH;
|
||||
return true;
|
||||
}
|
||||
|
||||
26
src/window.c
26
src/window.c
@ -440,13 +440,14 @@ static border_style_t border_style_from_motif_value(uint32_t value) {
|
||||
}
|
||||
|
||||
return BS_NORMAL;
|
||||
} else if (value & MWM_DECOR_TITLE) {
|
||||
return BS_NORMAL;
|
||||
} else if (value & MWM_DECOR_BORDER) {
|
||||
return BS_PIXEL;
|
||||
} else {
|
||||
return BS_NONE;
|
||||
}
|
||||
if (value & MWM_DECOR_TITLE) {
|
||||
return BS_NORMAL;
|
||||
}
|
||||
if (value & MWM_DECOR_BORDER) {
|
||||
return BS_PIXEL;
|
||||
}
|
||||
return BS_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -481,7 +482,7 @@ bool window_update_motif_hints(i3Window *win, xcb_get_property_reply_t *prop, bo
|
||||
* (64-bits long on amd64 for example). On the other hand,
|
||||
* xcb_get_property_value() behaves strictly according to documentation,
|
||||
* i.e. returns 32-bit data fields. */
|
||||
uint32_t *motif_hints = (uint32_t *)xcb_get_property_value(prop);
|
||||
uint32_t *motif_hints = xcb_get_property_value(prop);
|
||||
|
||||
if (motif_hints[MWM_HINTS_FLAGS_FIELD] & MWM_HINTS_DECORATIONS) {
|
||||
*motif_border_style = border_style_from_motif_value(motif_hints[MWM_HINTS_DECORATIONS_FIELD]);
|
||||
@ -530,7 +531,7 @@ void window_update_icon(i3Window *win, xcb_get_property_reply_t *prop) {
|
||||
}
|
||||
|
||||
uint32_t prop_value_len = xcb_get_property_value_length(prop);
|
||||
uint32_t *prop_value = (uint32_t *)xcb_get_property_value(prop);
|
||||
uint32_t *prop_value = xcb_get_property_value(prop);
|
||||
|
||||
/* Find an icon matching the preferred size.
|
||||
* If there is no such icon, take the smallest icon having at least
|
||||
@ -596,12 +597,11 @@ void window_update_icon(i3Window *win, xcb_get_property_reply_t *prop) {
|
||||
uint32_t *icon = smalloc(len * 4);
|
||||
|
||||
for (uint64_t i = 0; i < len; i++) {
|
||||
uint8_t r, g, b, a;
|
||||
const uint32_t pixel = data[2 + i];
|
||||
a = (pixel >> 24) & 0xff;
|
||||
r = (pixel >> 16) & 0xff;
|
||||
g = (pixel >> 8) & 0xff;
|
||||
b = (pixel >> 0) & 0xff;
|
||||
const uint8_t a = (pixel >> 24) & 0xff;
|
||||
uint8_t r = (pixel >> 16) & 0xff;
|
||||
uint8_t g = (pixel >> 8) & 0xff;
|
||||
uint8_t b = (pixel >> 0) & 0xff;
|
||||
|
||||
/* Cairo uses premultiplied alpha */
|
||||
r = (r * a) / 0xff;
|
||||
|
||||
@ -504,7 +504,7 @@ void workspace_show(Con *workspace) {
|
||||
if (focused->urgency_timer == NULL) {
|
||||
DLOG("Deferring reset of urgency flag of con %p on newly shown workspace %p\n",
|
||||
focused, workspace);
|
||||
focused->urgency_timer = scalloc(1, sizeof(struct ev_timer));
|
||||
focused->urgency_timer = scalloc(1, sizeof(ev_timer));
|
||||
/* use a repeating timer to allow for easy resets */
|
||||
ev_timer_init(focused->urgency_timer, workspace_defer_update_urgent_hint_cb,
|
||||
config.workspace_urgency_timer, config.workspace_urgency_timer);
|
||||
@ -1039,9 +1039,8 @@ Con *workspace_encapsulate(Con *ws) {
|
||||
|
||||
DLOG("Moving children of workspace %p / %s into container %p\n",
|
||||
ws, ws->name, new);
|
||||
Con *child;
|
||||
while (!TAILQ_EMPTY(&(ws->nodes_head))) {
|
||||
child = TAILQ_FIRST(&(ws->nodes_head));
|
||||
Con *child = TAILQ_FIRST(&(ws->nodes_head));
|
||||
con_detach(child);
|
||||
con_attach(child, new, true);
|
||||
}
|
||||
|
||||
43
src/x.c
43
src/x.c
@ -179,7 +179,7 @@ void x_con_init(Con *con) {
|
||||
(strlen("i3-frame") + 1) * 2,
|
||||
"i3-frame\0i3-frame\0");
|
||||
|
||||
struct con_state *state = scalloc(1, sizeof(struct con_state));
|
||||
con_state *state = scalloc(1, sizeof(struct con_state));
|
||||
state->id = con->frame.id;
|
||||
state->mapped = false;
|
||||
state->initial = true;
|
||||
@ -197,7 +197,7 @@ void x_con_init(Con *con) {
|
||||
*
|
||||
*/
|
||||
void x_reinit(Con *con) {
|
||||
struct con_state *state;
|
||||
con_state *state;
|
||||
|
||||
if ((state = state_for_frame(con->frame.id)) == NULL) {
|
||||
ELOG("window state not found\n");
|
||||
@ -217,7 +217,7 @@ void x_reinit(Con *con) {
|
||||
*
|
||||
*/
|
||||
void x_reparent_child(Con *con, Con *old) {
|
||||
struct con_state *state;
|
||||
con_state *state;
|
||||
if ((state = state_for_frame(con->frame.id)) == NULL) {
|
||||
ELOG("window state for con not found\n");
|
||||
return;
|
||||
@ -232,7 +232,7 @@ void x_reparent_child(Con *con, Con *old) {
|
||||
*
|
||||
*/
|
||||
void x_move_win(Con *src, Con *dest) {
|
||||
struct con_state *state_src, *state_dest;
|
||||
con_state *state_src, *state_dest;
|
||||
|
||||
if ((state_src = state_for_frame(src->frame.id)) == NULL) {
|
||||
ELOG("window state for src not found\n");
|
||||
@ -254,8 +254,6 @@ void x_move_win(Con *src, Con *dest) {
|
||||
}
|
||||
|
||||
static void _x_con_kill(Con *con) {
|
||||
con_state *state;
|
||||
|
||||
if (con->colormap != XCB_NONE) {
|
||||
xcb_free_colormap(conn, con->colormap);
|
||||
}
|
||||
@ -264,7 +262,7 @@ static void _x_con_kill(Con *con) {
|
||||
draw_util_surface_free(conn, &(con->frame_buffer));
|
||||
xcb_free_pixmap(conn, con->frame_buffer.id);
|
||||
con->frame_buffer.id = XCB_NONE;
|
||||
state = state_for_frame(con->frame.id);
|
||||
con_state *state = state_for_frame(con->frame.id);
|
||||
CIRCLEQ_REMOVE(&state_head, state, state);
|
||||
CIRCLEQ_REMOVE(&old_state_head, state, old_state);
|
||||
TAILQ_REMOVE(&initial_mapping_head, state, initial_mapping_order);
|
||||
@ -303,11 +301,10 @@ void x_con_reframe(Con *con) {
|
||||
*
|
||||
*/
|
||||
bool window_supports_protocol(xcb_window_t window, xcb_atom_t atom) {
|
||||
xcb_get_property_cookie_t cookie;
|
||||
xcb_icccm_get_wm_protocols_reply_t protocols;
|
||||
bool result = false;
|
||||
|
||||
cookie = xcb_icccm_get_wm_protocols(conn, window, A_WM_PROTOCOLS);
|
||||
xcb_get_property_cookie_t cookie = xcb_icccm_get_wm_protocols(conn, window, A_WM_PROTOCOLS);
|
||||
if (xcb_icccm_get_wm_protocols_reply(conn, cookie, &protocols, NULL) != 1) {
|
||||
return false;
|
||||
}
|
||||
@ -779,12 +776,12 @@ copy_pixmaps:
|
||||
*
|
||||
*/
|
||||
void x_deco_recurse(Con *con) {
|
||||
Con *current;
|
||||
bool leaf = TAILQ_EMPTY(&(con->nodes_head)) &&
|
||||
TAILQ_EMPTY(&(con->floating_head));
|
||||
con_state *state = state_for_frame(con->frame.id);
|
||||
const con_state *state = state_for_frame(con->frame.id);
|
||||
|
||||
if (!leaf) {
|
||||
Con *current;
|
||||
TAILQ_FOREACH (current, &(con->nodes_head), nodes) {
|
||||
x_deco_recurse(current);
|
||||
}
|
||||
@ -906,7 +903,7 @@ static void set_shape_state(Con *con, bool need_reshape) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct con_state *state;
|
||||
con_state *state;
|
||||
if ((state = state_for_frame(con->frame.id)) == NULL) {
|
||||
ELOG("window state for con %p not found\n", con);
|
||||
return;
|
||||
@ -941,10 +938,9 @@ static void set_shape_state(Con *con, bool need_reshape) {
|
||||
*/
|
||||
void x_push_node(Con *con) {
|
||||
Con *current;
|
||||
con_state *state;
|
||||
Rect rect = con->rect;
|
||||
|
||||
state = state_for_frame(con->frame.id);
|
||||
con_state *state = state_for_frame(con->frame.id);
|
||||
|
||||
if (state->name != NULL) {
|
||||
DLOG("pushing name %s for con %p\n", state->name, con);
|
||||
@ -1216,15 +1212,12 @@ void x_push_node(Con *con) {
|
||||
*/
|
||||
static void x_push_node_unmaps(Con *con) {
|
||||
Con *current;
|
||||
con_state *state;
|
||||
|
||||
state = state_for_frame(con->frame.id);
|
||||
con_state *state = state_for_frame(con->frame.id);
|
||||
|
||||
/* map/unmap if map state changed, also ensure that the child window
|
||||
* is changed if we are mapped *and* in initial state (meaning the
|
||||
* container was empty before, but now got a child) */
|
||||
if (state->unmap_now) {
|
||||
xcb_void_cookie_t cookie;
|
||||
if (con->window != NULL) {
|
||||
/* Set WM_STATE_WITHDRAWN, it seems like Java apps need it */
|
||||
long data[] = {XCB_ICCCM_WM_STATE_WITHDRAWN, XCB_NONE};
|
||||
@ -1232,7 +1225,7 @@ static void x_push_node_unmaps(Con *con) {
|
||||
A_WM_STATE, A_WM_STATE, 32, 2, data);
|
||||
}
|
||||
|
||||
cookie = xcb_unmap_window(conn, con->frame.id);
|
||||
const xcb_void_cookie_t cookie = xcb_unmap_window(conn, con->frame.id);
|
||||
DLOG("unmapping container %p / %s (serial %d)\n", con, con->name, cookie.sequence);
|
||||
/* we need to increase ignore_unmap for this container (if it
|
||||
* contains a window) and for every window "under" this one which
|
||||
@ -1498,10 +1491,8 @@ void x_push_changes(Con *con) {
|
||||
* next call to x_push_changes() will make the change visible in X11.
|
||||
*
|
||||
*/
|
||||
void x_raise_con(Con *con) {
|
||||
con_state *state;
|
||||
state = state_for_frame(con->frame.id);
|
||||
|
||||
void x_raise_con(const Con *con) {
|
||||
con_state *state = state_for_frame(con->frame.id);
|
||||
CIRCLEQ_REMOVE(&state_head, state, state);
|
||||
CIRCLEQ_INSERT_HEAD(&state_head, state, state);
|
||||
}
|
||||
@ -1513,8 +1504,7 @@ void x_raise_con(Con *con) {
|
||||
*
|
||||
*/
|
||||
void x_set_name(Con *con, const char *name) {
|
||||
struct con_state *state;
|
||||
|
||||
con_state *state;
|
||||
if ((state = state_for_frame(con->frame.id)) == NULL) {
|
||||
ELOG("window state not found\n");
|
||||
return;
|
||||
@ -1587,8 +1577,7 @@ void x_mask_event_mask(uint32_t mask) {
|
||||
* Enables or disables nonrectangular shape of the container frame.
|
||||
*/
|
||||
void x_set_shape(Con *con, xcb_shape_sk_t kind, bool enable) {
|
||||
struct con_state *state;
|
||||
if ((state = state_for_frame(con->frame.id)) == NULL) {
|
||||
if (state_for_frame(con->frame.id) == NULL) {
|
||||
ELOG("window state for con %p not found\n", con);
|
||||
return;
|
||||
}
|
||||
|
||||
19
src/xcb.c
19
src/xcb.c
@ -104,14 +104,13 @@ void send_take_focus(xcb_window_t window, xcb_timestamp_t timestamp) {
|
||||
* Configures the given window to have the size/position specified by given rect
|
||||
*
|
||||
*/
|
||||
void xcb_set_window_rect(xcb_connection_t *conn, xcb_window_t window, Rect r) {
|
||||
xcb_void_cookie_t cookie;
|
||||
cookie = xcb_configure_window(conn, window,
|
||||
XCB_CONFIG_WINDOW_X |
|
||||
XCB_CONFIG_WINDOW_Y |
|
||||
XCB_CONFIG_WINDOW_WIDTH |
|
||||
XCB_CONFIG_WINDOW_HEIGHT,
|
||||
&(r.x));
|
||||
void xcb_set_window_rect(xcb_connection_t *conn, const xcb_window_t window, Rect r) {
|
||||
xcb_void_cookie_t cookie = xcb_configure_window(conn, window,
|
||||
XCB_CONFIG_WINDOW_X |
|
||||
XCB_CONFIG_WINDOW_Y |
|
||||
XCB_CONFIG_WINDOW_WIDTH |
|
||||
XCB_CONFIG_WINDOW_HEIGHT,
|
||||
&(r.x));
|
||||
/* ignore events which are generated because we configured a window */
|
||||
add_ignore_event(cookie.sequence, -1);
|
||||
}
|
||||
@ -205,9 +204,7 @@ xcb_visualid_t get_visualid_by_depth(uint16_t depth) {
|
||||
continue;
|
||||
}
|
||||
|
||||
xcb_visualtype_iterator_t visual_iter;
|
||||
|
||||
visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
|
||||
xcb_visualtype_iterator_t visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
|
||||
if (!visual_iter.rem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -36,15 +36,12 @@ static Output *get_screen_at(unsigned int x, unsigned int y) {
|
||||
*
|
||||
*/
|
||||
static void query_screens(xcb_connection_t *conn) {
|
||||
xcb_xinerama_query_screens_reply_t *reply;
|
||||
xcb_xinerama_screen_info_t *screen_info;
|
||||
|
||||
reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
|
||||
xcb_xinerama_query_screens_reply_t *reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
|
||||
if (!reply) {
|
||||
ELOG("Couldn't get Xinerama screens\n");
|
||||
return;
|
||||
}
|
||||
screen_info = xcb_xinerama_query_screens_screen_info(reply);
|
||||
const xcb_xinerama_screen_info_t *screen_info = xcb_xinerama_query_screens_screen_info(reply);
|
||||
int screens = xcb_xinerama_query_screens_screen_info_length(reply);
|
||||
|
||||
for (int screen = 0; screen < screens; screen++) {
|
||||
@ -114,8 +111,7 @@ void xinerama_init(void) {
|
||||
DLOG("Xinerama extension not found, using root output.\n");
|
||||
use_root_output(conn);
|
||||
} else {
|
||||
xcb_xinerama_is_active_reply_t *reply;
|
||||
reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL);
|
||||
xcb_xinerama_is_active_reply_t *reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL);
|
||||
|
||||
if (reply == NULL || !reply->state) {
|
||||
DLOG("Xinerama is not active (in your X-Server), using root output.\n");
|
||||
|
||||
Reference in New Issue
Block a user