Skip to content

Commit

Permalink
Merge branch 'master' into sort-workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
epontan committed Mar 26, 2024
2 parents e8cc8d0 + 5a7477c commit 252a04f
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 11 deletions.
3 changes: 3 additions & 0 deletions include/sway/input/input-manager.h
Expand Up @@ -4,6 +4,7 @@
#include <wlr/types/wlr_keyboard_shortcuts_inhibit_v1.h>
#include <wlr/types/wlr_virtual_keyboard_v1.h>
#include <wlr/types/wlr_virtual_pointer_v1.h>
#include <wlr/types/wlr_transient_seat_v1.h>
#include "sway/server.h"
#include "sway/config.h"
#include "list.h"
Expand All @@ -24,13 +25,15 @@ struct sway_input_manager {
struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard;
struct wlr_virtual_pointer_manager_v1 *virtual_pointer;
struct wlr_pointer_gestures_v1 *pointer_gestures;
struct wlr_transient_seat_manager_v1 *transient_seat_manager;

struct wl_listener new_input;
struct wl_listener inhibit_activate;
struct wl_listener inhibit_deactivate;
struct wl_listener keyboard_shortcuts_inhibit_new_inhibitor;
struct wl_listener virtual_keyboard_new;
struct wl_listener virtual_pointer_new;
struct wl_listener transient_seat_create;
};

struct sway_input_manager *input_manager_create(struct sway_server *server);
Expand Down
1 change: 1 addition & 0 deletions include/sway/input/seat.h
Expand Up @@ -124,6 +124,7 @@ struct sway_seat {
struct wl_listener start_drag;
struct wl_listener request_set_selection;
struct wl_listener request_set_primary_selection;
struct wl_listener destroy;

struct wl_list devices; // sway_seat_device::link
struct wl_list keyboard_groups; // sway_keyboard_group::link
Expand Down
1 change: 1 addition & 0 deletions include/sway/server.h
Expand Up @@ -46,6 +46,7 @@ struct sway_server {

struct wl_listener new_output;
struct wl_listener output_layout_change;
struct wl_listener renderer_lost;

struct wlr_idle_notifier_v1 *idle_notifier_v1;
struct sway_idle_inhibit_manager_v1 idle_inhibit_manager_v1;
Expand Down
12 changes: 10 additions & 2 deletions sway/desktop/output.c
Expand Up @@ -183,7 +183,15 @@ static void send_frame_done_iterator(struct wlr_scene_buffer *buffer,
}
}

static enum wlr_scale_filter_mode get_scale_filter(struct sway_output *output) {
static enum wlr_scale_filter_mode get_scale_filter(struct sway_output *output,
struct wlr_scene_buffer *buffer) {
// if we are scaling down, we should always choose linear
if (buffer->dst_width > 0 && buffer->dst_height > 0 && (
buffer->dst_width < buffer->buffer_width ||
buffer->dst_height < buffer->buffer_height)) {
return WLR_SCALE_FILTER_BILINEAR;
}

switch (output->scale_filter) {
case SCALE_FILTER_LINEAR:
return WLR_SCALE_FILTER_BILINEAR;
Expand Down Expand Up @@ -212,7 +220,7 @@ static void output_configure_scene(struct sway_output *output,
// hack: don't call the scene setter because that will damage all outputs
// We don't want to damage outputs that aren't our current output that
// we're configuring
buffer->filter_mode = get_scale_filter(output);
buffer->filter_mode = get_scale_filter(output, buffer);

wlr_scene_buffer_set_opacity(buffer, opacity);
} else if (node->type == WLR_SCENE_NODE_TREE) {
Expand Down
25 changes: 25 additions & 0 deletions sway/input/input-manager.c
Expand Up @@ -2,7 +2,9 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <wlr/config.h>
#include <wlr/backend/libinput.h>
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_keyboard_group.h>
#include <wlr/types/wlr_virtual_keyboard_v1.h>
Expand Down Expand Up @@ -431,6 +433,20 @@ void handle_virtual_pointer(struct wl_listener *listener, void *data) {
}
}

static void handle_transient_seat_manager_create_seat(
struct wl_listener *listener, void *data) {
struct wlr_transient_seat_v1 *transient_seat = data;
static uint64_t i;
char name[256];
snprintf(name, sizeof(name), "transient-%"PRIx64, i++);
struct sway_seat *seat = seat_create(name);
if (seat && seat->wlr_seat) {
wlr_transient_seat_v1_ready(transient_seat, seat->wlr_seat);
} else {
wlr_transient_seat_v1_deny(transient_seat);
}
}

struct sway_input_manager *input_manager_create(struct sway_server *server) {
struct sway_input_manager *input =
calloc(1, sizeof(struct sway_input_manager));
Expand Down Expand Up @@ -466,6 +482,15 @@ struct sway_input_manager *input_manager_create(struct sway_server *server) {

input->pointer_gestures = wlr_pointer_gestures_v1_create(server->wl_display);

input->transient_seat_manager =
wlr_transient_seat_manager_v1_create(server->wl_display);
assert(input->transient_seat_manager);

input->transient_seat_create.notify =
handle_transient_seat_manager_create_seat;
wl_signal_add(&input->transient_seat_manager->events.create_seat,
&input->transient_seat_create);

return input;
}

Expand Down
11 changes: 10 additions & 1 deletion sway/input/seat.c
Expand Up @@ -67,6 +67,12 @@ static void seat_node_destroy(struct sway_seat_node *seat_node) {
}

void seat_destroy(struct sway_seat *seat) {
wlr_seat_destroy(seat->wlr_seat);
}

static void handle_seat_destroy(struct wl_listener *listener, void *data) {
struct sway_seat *seat = wl_container_of(listener, seat, destroy);

if (seat == config->handler_context.seat) {
config->handler_context.seat = input_manager_get_default_seat();
}
Expand All @@ -87,7 +93,7 @@ void seat_destroy(struct sway_seat *seat) {
wl_list_remove(&seat->request_set_selection.link);
wl_list_remove(&seat->request_set_primary_selection.link);
wl_list_remove(&seat->link);
wlr_seat_destroy(seat->wlr_seat);
wl_list_remove(&seat->destroy.link);
for (int i = 0; i < seat->deferred_bindings->length; i++) {
free_sway_binding(seat->deferred_bindings->items[i]);
}
Expand Down Expand Up @@ -534,6 +540,9 @@ struct sway_seat *seat_create(const char *seat_name) {
return NULL;
}

seat->destroy.notify = handle_seat_destroy;
wl_signal_add(&seat->wlr_seat->events.destroy, &seat->destroy);

seat->idle_inhibit_sources = seat->idle_wake_sources =
IDLE_SOURCE_KEYBOARD |
IDLE_SOURCE_POINTER |
Expand Down
46 changes: 45 additions & 1 deletion sway/server.c
Expand Up @@ -112,7 +112,8 @@ static bool is_privileged(const struct wl_global *global) {
global == server.session_lock.manager->global ||
global == server.input->keyboard_shortcuts_inhibit->global ||
global == server.input->virtual_keyboard->global ||
global == server.input->virtual_pointer->global;
global == server.input->virtual_pointer->global ||
global == server.input->transient_seat_manager->global;
}

static bool filter_global(const struct wl_client *client,
Expand Down Expand Up @@ -172,6 +173,45 @@ static void detect_proprietary(struct wlr_backend *backend, void *data) {
drmFreeVersion(version);
}

static void handle_renderer_lost(struct wl_listener *listener, void *data) {
struct sway_server *server = wl_container_of(listener, server, renderer_lost);

sway_log(SWAY_INFO, "Re-creating renderer after GPU reset");

struct wlr_renderer *renderer = wlr_renderer_autocreate(server->backend);
if (renderer == NULL) {
sway_log(SWAY_ERROR, "Unable to create renderer");
return;
}

struct wlr_allocator *allocator =
wlr_allocator_autocreate(server->backend, renderer);
if (allocator == NULL) {
sway_log(SWAY_ERROR, "Unable to create allocator");
wlr_renderer_destroy(renderer);
return;
}

struct wlr_renderer *old_renderer = server->renderer;
struct wlr_allocator *old_allocator = server->allocator;
server->renderer = renderer;
server->allocator = allocator;

wl_list_remove(&server->renderer_lost.link);
wl_signal_add(&server->renderer->events.lost, &server->renderer_lost);

wlr_compositor_set_renderer(server->compositor, renderer);

for (int i = 0; i < root->outputs->length; ++i) {
struct sway_output *output = root->outputs->items[i];
wlr_output_init_render(output->wlr_output,
server->allocator, server->renderer);
}

wlr_allocator_destroy(old_allocator);
wlr_renderer_destroy(old_renderer);
}

bool server_init(struct sway_server *server) {
sway_log(SWAY_DEBUG, "Initializing Wayland server");
server->wl_display = wl_display_create();
Expand All @@ -195,6 +235,9 @@ bool server_init(struct sway_server *server) {
return false;
}

server->renderer_lost.notify = handle_renderer_lost;
wl_signal_add(&server->renderer->events.lost, &server->renderer_lost);

wlr_renderer_init_wl_shm(server->renderer, server->wl_display);

if (wlr_renderer_get_dmabuf_texture_formats(server->renderer) != NULL) {
Expand Down Expand Up @@ -399,6 +442,7 @@ void server_fini(struct sway_server *server) {
wlr_xwayland_destroy(server->xwayland.wlr_xwayland);
#endif
wl_display_destroy_clients(server->wl_display);
wlr_backend_destroy(server->backend);
wl_display_destroy(server->wl_display);
list_free(server->dirty_nodes);
}
Expand Down
12 changes: 5 additions & 7 deletions sway/sway-output.5.scd
Expand Up @@ -72,13 +72,11 @@ must be separated by one space. For example:

*output* <name> scale <factor>
Scales the specified output by the specified scale _factor_. An integer is
recommended, but fractional values are also supported. If a fractional
value are specified, be warned that it is not possible to faithfully
represent the contents of your windows - they will be rendered at the next
highest integer scale factor and downscaled. You may be better served by
setting an integer scale factor and adjusting the font size of your
applications to taste. HiDPI isn't supported with Xwayland clients (windows
will blur).
recommended, but fractional values are also supported. You may be better
served by setting an integer scale factor and adjusting the font size of
your applications to taste. HiDPI isn't supported with Xwayland clients
(windows will blur). A fractional scale may be slightly adjusted to match
requirements of the protocol.

*output* <name> scale_filter linear|nearest|smart
Indicates how to scale application buffers that are rendered at a scale
Expand Down

0 comments on commit 252a04f

Please sign in to comment.