mirror of
https://github.com/swaywm/sway.git
synced 2024-11-24 08:51:27 +00:00
Replace expensive seat_get_config() functions with pointer
This commit is contained in:
parent
980a4e0211
commit
6b87ec4aea
|
@ -74,10 +74,6 @@ struct sway_cursor {
|
||||||
|
|
||||||
struct wl_event_source *hide_source;
|
struct wl_event_source *hide_source;
|
||||||
bool hidden;
|
bool hidden;
|
||||||
// This field is just a cache of the field in seat_config in order to avoid
|
|
||||||
// costly seat_config lookups on every keypress. HIDE_WHEN_TYPING_DEFAULT
|
|
||||||
// indicates that there is no cached value.
|
|
||||||
enum seat_config_hide_cursor_when_typing hide_when_typing;
|
|
||||||
|
|
||||||
size_t pressed_button_count;
|
size_t pressed_button_count;
|
||||||
};
|
};
|
||||||
|
|
|
@ -83,6 +83,7 @@ struct sway_drag {
|
||||||
struct sway_seat {
|
struct sway_seat {
|
||||||
struct wlr_seat *wlr_seat;
|
struct wlr_seat *wlr_seat;
|
||||||
struct sway_cursor *cursor;
|
struct sway_cursor *cursor;
|
||||||
|
struct seat_config *config;
|
||||||
|
|
||||||
// Seat scene tree structure
|
// Seat scene tree structure
|
||||||
// - scene_tree
|
// - scene_tree
|
||||||
|
@ -243,10 +244,6 @@ void seat_for_each_node(struct sway_seat *seat,
|
||||||
|
|
||||||
void seat_apply_config(struct sway_seat *seat, struct seat_config *seat_config);
|
void seat_apply_config(struct sway_seat *seat, struct seat_config *seat_config);
|
||||||
|
|
||||||
struct seat_config *seat_get_config(struct sway_seat *seat);
|
|
||||||
|
|
||||||
struct seat_config *seat_get_config_by_name(const char *name);
|
|
||||||
|
|
||||||
void seat_idle_notify_activity(struct sway_seat *seat,
|
void seat_idle_notify_activity(struct sway_seat *seat,
|
||||||
enum sway_input_idle_source source);
|
enum sway_input_idle_source source);
|
||||||
|
|
||||||
|
|
|
@ -37,12 +37,6 @@ struct cmd_results *seat_cmd_hide_cursor(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
seat_config->hide_cursor_when_typing = parse_boolean(argv[1], true) ?
|
seat_config->hide_cursor_when_typing = parse_boolean(argv[1], true) ?
|
||||||
HIDE_WHEN_TYPING_ENABLE : HIDE_WHEN_TYPING_DISABLE;
|
HIDE_WHEN_TYPING_ENABLE : HIDE_WHEN_TYPING_DISABLE;
|
||||||
|
|
||||||
// Invalidate all the caches for this config
|
|
||||||
struct sway_seat *seat = NULL;
|
|
||||||
wl_list_for_each(seat, &server.input->seats, link) {
|
|
||||||
seat->cursor->hide_when_typing = HIDE_WHEN_TYPING_DEFAULT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||||
|
|
|
@ -198,10 +198,8 @@ int cursor_get_timeout(struct sway_cursor *cursor) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct seat_config *sc = seat_get_config(cursor->seat);
|
struct seat_config *sc = cursor->seat->config;
|
||||||
if (!sc) {
|
|
||||||
sc = seat_get_config_by_name("*");
|
|
||||||
}
|
|
||||||
int timeout = sc ? sc->hide_cursor_timeout : 0;
|
int timeout = sc ? sc->hide_cursor_timeout : 0;
|
||||||
if (timeout < 0) {
|
if (timeout < 0) {
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
|
@ -214,23 +212,7 @@ void cursor_notify_key_press(struct sway_cursor *cursor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cursor->hide_when_typing == HIDE_WHEN_TYPING_DEFAULT) {
|
if (cursor->seat->config->hide_cursor_when_typing == HIDE_WHEN_TYPING_ENABLE) {
|
||||||
// No cached value, need to lookup in the seat_config
|
|
||||||
const struct seat_config *seat_config = seat_get_config(cursor->seat);
|
|
||||||
if (!seat_config) {
|
|
||||||
seat_config = seat_get_config_by_name("*");
|
|
||||||
if (!seat_config) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cursor->hide_when_typing = seat_config->hide_cursor_when_typing;
|
|
||||||
// The default is currently disabled
|
|
||||||
if (cursor->hide_when_typing == HIDE_WHEN_TYPING_DEFAULT) {
|
|
||||||
cursor->hide_when_typing = HIDE_WHEN_TYPING_DISABLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cursor->hide_when_typing == HIDE_WHEN_TYPING_ENABLE) {
|
|
||||||
cursor_hide(cursor);
|
cursor_hide(cursor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1339,10 +1321,7 @@ void handle_pointer_constraint(struct wl_listener *listener, void *data) {
|
||||||
|
|
||||||
void sway_cursor_constrain(struct sway_cursor *cursor,
|
void sway_cursor_constrain(struct sway_cursor *cursor,
|
||||||
struct wlr_pointer_constraint_v1 *constraint) {
|
struct wlr_pointer_constraint_v1 *constraint) {
|
||||||
struct seat_config *config = seat_get_config(cursor->seat);
|
struct seat_config *config = cursor->seat->config;
|
||||||
if (!config) {
|
|
||||||
config = seat_get_config_by_name("*");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!config || config->allow_constrain == CONSTRAIN_DISABLE) {
|
if (!config || config->allow_constrain == CONSTRAIN_DISABLE) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -175,7 +175,15 @@ static struct sway_input_device *input_sway_device_from_wlr(
|
||||||
static bool input_has_seat_fallback_configuration(void) {
|
static bool input_has_seat_fallback_configuration(void) {
|
||||||
struct sway_seat *seat = NULL;
|
struct sway_seat *seat = NULL;
|
||||||
wl_list_for_each(seat, &server.input->seats, link) {
|
wl_list_for_each(seat, &server.input->seats, link) {
|
||||||
struct seat_config *seat_config = seat_get_config(seat);
|
struct seat_config *seat_config = NULL;
|
||||||
|
struct seat_config *sc = NULL;
|
||||||
|
for (int i = 0; i < config->seat_configs->length; ++i ) {
|
||||||
|
sc = config->seat_configs->items[i];
|
||||||
|
if (strcmp(seat->wlr_seat->name, sc->name) == 0) {
|
||||||
|
seat_config = sc;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (seat_config && strcmp(seat_config->name, "*") != 0
|
if (seat_config && strcmp(seat_config->name, "*") != 0
|
||||||
&& seat_config->fallback != -1) {
|
&& seat_config->fallback != -1) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -257,10 +265,9 @@ static void handle_new_input(struct wl_listener *listener, void *data) {
|
||||||
bool added = false;
|
bool added = false;
|
||||||
struct sway_seat *seat = NULL;
|
struct sway_seat *seat = NULL;
|
||||||
wl_list_for_each(seat, &input->seats, link) {
|
wl_list_for_each(seat, &input->seats, link) {
|
||||||
struct seat_config *seat_config = seat_get_config(seat);
|
bool has_attachment = seat->config &&
|
||||||
bool has_attachment = seat_config &&
|
(seat_config_get_attachment(seat->config, input_device->identifier) ||
|
||||||
(seat_config_get_attachment(seat_config, input_device->identifier) ||
|
seat_config_get_attachment(seat->config, "*"));
|
||||||
seat_config_get_attachment(seat_config, "*"));
|
|
||||||
|
|
||||||
if (has_attachment) {
|
if (has_attachment) {
|
||||||
seat_add_device(seat, input_device);
|
seat_add_device(seat, input_device);
|
||||||
|
@ -270,8 +277,7 @@ static void handle_new_input(struct wl_listener *listener, void *data) {
|
||||||
|
|
||||||
if (!added) {
|
if (!added) {
|
||||||
wl_list_for_each(seat, &input->seats, link) {
|
wl_list_for_each(seat, &input->seats, link) {
|
||||||
struct seat_config *seat_config = seat_get_config(seat);
|
if (seat->config && seat->config->fallback == 1) {
|
||||||
if (seat_config && seat_config->fallback == 1) {
|
|
||||||
seat_add_device(seat, input_device);
|
seat_add_device(seat, input_device);
|
||||||
added = true;
|
added = true;
|
||||||
}
|
}
|
||||||
|
@ -336,13 +342,8 @@ static void handle_keyboard_shortcuts_inhibit_new_inhibitor(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inhibit == SHORTCUTS_INHIBIT_DEFAULT) {
|
if (inhibit == SHORTCUTS_INHIBIT_DEFAULT) {
|
||||||
struct seat_config *config = seat_get_config(seat);
|
if (seat->config) {
|
||||||
if (!config) {
|
inhibit = seat->config->shortcuts_inhibit;
|
||||||
config = seat_get_config_by_name("*");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config) {
|
|
||||||
inhibit = config->shortcuts_inhibit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -631,9 +632,9 @@ void input_manager_apply_seat_config(struct seat_config *seat_config) {
|
||||||
if (strcmp(seat_config->name, "*") == 0) {
|
if (strcmp(seat_config->name, "*") == 0) {
|
||||||
struct sway_seat *seat = NULL;
|
struct sway_seat *seat = NULL;
|
||||||
wl_list_for_each(seat, &server.input->seats, link) {
|
wl_list_for_each(seat, &server.input->seats, link) {
|
||||||
// Only apply the wildcard config directly if there is no seat
|
// Only apply the wildcard config directly if there is no seatz
|
||||||
// specific config
|
// specific config
|
||||||
struct seat_config *sc = seat_get_config(seat);
|
struct seat_config *sc = seat->config;
|
||||||
if (!sc) {
|
if (!sc) {
|
||||||
sc = seat_config;
|
sc = seat_config;
|
||||||
}
|
}
|
||||||
|
@ -655,7 +656,7 @@ void input_manager_apply_seat_config(struct seat_config *seat_config) {
|
||||||
list_t *seat_list = create_list();
|
list_t *seat_list = create_list();
|
||||||
struct sway_seat *seat = NULL;
|
struct sway_seat *seat = NULL;
|
||||||
wl_list_for_each(seat, &server.input->seats, link) {
|
wl_list_for_each(seat, &server.input->seats, link) {
|
||||||
struct seat_config *seat_config = seat_get_config(seat);
|
struct seat_config *seat_config = seat->config;
|
||||||
if (!seat_config) {
|
if (!seat_config) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -683,8 +684,7 @@ void input_manager_apply_seat_config(struct seat_config *seat_config) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
wl_list_for_each(seat, &server.input->seats, link) {
|
wl_list_for_each(seat, &server.input->seats, link) {
|
||||||
struct seat_config *seat_config = seat_get_config(seat);
|
if (seat->config && seat->config->fallback == 1) {
|
||||||
if (seat_config && seat_config->fallback == 1) {
|
|
||||||
seat_add_device(seat, input_device);
|
seat_add_device(seat, input_device);
|
||||||
} else {
|
} else {
|
||||||
seat_remove_device(seat, input_device);
|
seat_remove_device(seat, input_device);
|
||||||
|
|
|
@ -831,10 +831,7 @@ static void sway_keyboard_group_remove_invalid(struct sway_keyboard *keyboard) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sway_seat *seat = keyboard->seat_device->sway_seat;
|
struct sway_seat *seat = keyboard->seat_device->sway_seat;
|
||||||
struct seat_config *sc = seat_get_config(seat);
|
struct seat_config *sc = seat->config;
|
||||||
if (!sc) {
|
|
||||||
sc = seat_get_config_by_name("*");
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (sc ? sc->keyboard_grouping : KEYBOARD_GROUP_DEFAULT) {
|
switch (sc ? sc->keyboard_grouping : KEYBOARD_GROUP_DEFAULT) {
|
||||||
case KEYBOARD_GROUP_NONE:
|
case KEYBOARD_GROUP_NONE:
|
||||||
|
@ -854,17 +851,13 @@ static void sway_keyboard_group_remove_invalid(struct sway_keyboard *keyboard) {
|
||||||
static void sway_keyboard_group_add(struct sway_keyboard *keyboard) {
|
static void sway_keyboard_group_add(struct sway_keyboard *keyboard) {
|
||||||
struct sway_input_device *device = keyboard->seat_device->input_device;
|
struct sway_input_device *device = keyboard->seat_device->input_device;
|
||||||
struct sway_seat *seat = keyboard->seat_device->sway_seat;
|
struct sway_seat *seat = keyboard->seat_device->sway_seat;
|
||||||
struct seat_config *sc = seat_get_config(seat);
|
struct seat_config *sc = seat->config;
|
||||||
|
|
||||||
if (device->is_virtual) {
|
if (device->is_virtual) {
|
||||||
// Virtual devices should not be grouped
|
// Virtual devices should not be grouped
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sc) {
|
|
||||||
sc = seat_get_config_by_name("*");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sc && sc->keyboard_grouping == KEYBOARD_GROUP_NONE) {
|
if (sc && sc->keyboard_grouping == KEYBOARD_GROUP_NONE) {
|
||||||
// Keyboard grouping is disabled for the seat
|
// Keyboard grouping is disabled for the seat
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -984,13 +984,9 @@ void seat_configure_xcursor(struct sway_seat *seat) {
|
||||||
unsigned cursor_size = 24;
|
unsigned cursor_size = 24;
|
||||||
const char *cursor_theme = NULL;
|
const char *cursor_theme = NULL;
|
||||||
|
|
||||||
const struct seat_config *seat_config = seat_get_config(seat);
|
if (seat->config) {
|
||||||
if (!seat_config) {
|
cursor_size = seat->config->xcursor_theme.size;
|
||||||
seat_config = seat_get_config_by_name("*");
|
cursor_theme = seat->config->xcursor_theme.name;
|
||||||
}
|
|
||||||
if (seat_config) {
|
|
||||||
cursor_size = seat_config->xcursor_theme.size;
|
|
||||||
cursor_theme = seat_config->xcursor_theme.name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seat == input_manager_get_default_seat()) {
|
if (seat == input_manager_get_default_seat()) {
|
||||||
|
@ -1493,8 +1489,7 @@ void seat_apply_config(struct sway_seat *seat,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
seat->idle_inhibit_sources = seat_config->idle_inhibit_sources;
|
seat->config = seat_config;
|
||||||
seat->idle_wake_sources = seat_config->idle_wake_sources;
|
|
||||||
|
|
||||||
wl_list_for_each(seat_device, &seat->devices, link) {
|
wl_list_for_each(seat_device, &seat->devices, link) {
|
||||||
seat_configure_device(seat, seat_device->input_device);
|
seat_configure_device(seat, seat_device->input_device);
|
||||||
|
@ -1503,30 +1498,6 @@ void seat_apply_config(struct sway_seat *seat,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct seat_config *seat_get_config(struct sway_seat *seat) {
|
|
||||||
struct seat_config *seat_config = NULL;
|
|
||||||
for (int i = 0; i < config->seat_configs->length; ++i ) {
|
|
||||||
seat_config = config->seat_configs->items[i];
|
|
||||||
if (strcmp(seat->wlr_seat->name, seat_config->name) == 0) {
|
|
||||||
return seat_config;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct seat_config *seat_get_config_by_name(const char *name) {
|
|
||||||
struct seat_config *seat_config = NULL;
|
|
||||||
for (int i = 0; i < config->seat_configs->length; ++i ) {
|
|
||||||
seat_config = config->seat_configs->items[i];
|
|
||||||
if (strcmp(name, seat_config->name) == 0) {
|
|
||||||
return seat_config;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void seat_pointer_notify_button(struct sway_seat *seat, uint32_t time_msec,
|
void seat_pointer_notify_button(struct sway_seat *seat, uint32_t time_msec,
|
||||||
uint32_t button, enum wl_pointer_button_state state) {
|
uint32_t button, enum wl_pointer_button_state state) {
|
||||||
seat->last_button_serial = wlr_seat_pointer_notify_button(seat->wlr_seat,
|
seat->last_button_serial = wlr_seat_pointer_notify_button(seat->wlr_seat,
|
||||||
|
|
Loading…
Reference in a new issue