improve session lock support stability

This commit is contained in:
DanyLE 2024-04-17 01:08:26 +02:00
parent 5b29514b09
commit 4a7219f03c
3 changed files with 109 additions and 97 deletions

197
session.c
View File

@ -8,58 +8,62 @@
static struct wl_listener g_lock_new;
static struct wl_listener g_lock_manager_destroy;
static struct wlr_session_lock_manager_v1 *g_session_lock_manager;
static struct diyac_server * g_server;
static struct diyac_server *g_server;
static void focus_output(struct diyac_output * output)
static void focus_output(struct diyac_output *output)
{
g_server->lock->focused = NULL;
if(output)
if (output)
{
g_server->lock->focused = output->lock_handle->surface->surface;
}
diyac_seat_focus_lock_surface(&g_server->seat, g_server->lock->focused);
}
static void session_lock_update_geometry(struct diyac_output* output, bool align)
static void session_lock_update_geometry(struct diyac_output *output, bool align)
{
struct wlr_box box;
if(align)
wlr_output_layout_get_box(g_server->output_layout, output->wlr_output, &box);
if (align)
{
wlr_output_layout_get_box(g_server->output_layout, output->wlr_output, &box);
wlr_scene_node_set_position(&output->scenes.session->node, box.x, box.y);
wlr_scene_node_set_position(&output->scenes.session->node, box.x, box.y);
wlr_log(WLR_INFO, "session_lock_update_geometry: Align lock screen on %d, %d", box.x, box.y);
}
wlr_scene_rect_set_size(output->lock_handle->background, box.width, box.height);
if (output->lock_handle->surface) {
wlr_session_lock_surface_v1_configure(output->lock_handle->surface, box.width, box.height);
}
if (output->lock_handle->surface)
{
wlr_log(WLR_INFO, "session_lock_update_geometry: configure lock screen %d, %d", box.width, box.height);
wlr_session_lock_surface_v1_configure(output->lock_handle->surface, box.width, box.height);
}
}
static void handle_surface_map(struct wl_listener *listener, void *data)
{
struct diyac_output_lock_handle *handle = wl_container_of(listener, handle, surface_map);
if (!g_server->lock->focused)
struct diyac_output_lock_handle *handle = wl_container_of(listener, handle, surface_map);
if (!g_server->lock->focused)
{
focus_output(handle->output);
}
}
wlr_log(WLR_INFO, "handle_surface_map: surface is mapped");
}
static void handle_surface_destroy(struct wl_listener *listener, void *data)
{
struct diyac_output_lock_handle *handle = wl_container_of(listener, handle, surface_destroy);
if(g_server->lock->focused == handle->surface->surface)
struct diyac_output_lock_handle *handle = wl_container_of(listener, handle, surface_destroy);
if (g_server->lock->focused == handle->surface->surface)
{
struct diyac_output *output;
wl_list_for_each(output, &g_server->outputs, link)
{
if(output == handle->output ||
if (output == handle->output ||
!output->lock_handle ||
!output->lock_handle->surface ||
!output->lock_handle->surface->surface)
{
continue;
}
if(output->lock_handle->surface->surface->mapped)
if (output->lock_handle->surface->surface->mapped)
{
// focus surface
focus_output(output);
@ -68,130 +72,132 @@ static void handle_surface_destroy(struct wl_listener *listener, void *data)
}
focus_output(NULL);
}
assert(handle->surface);
handle->surface = NULL;
wl_list_remove(&handle->surface_destroy.link);
wl_list_remove(&handle->surface_map.link);
wlr_log(WLR_INFO, "handle_surface_destroy: Lock surface destroyed");
assert(handle->surface);
handle->surface = NULL;
wl_list_remove(&handle->surface_destroy.link);
wl_list_remove(&handle->surface_map.link);
}
static void handle_new_surface(struct wl_listener *listener, void *data)
{
struct diyac_session_lock *lock = wl_container_of(listener, lock, new_surface);
struct wlr_session_lock_surface_v1 *lock_surface = data;
struct diyac_output *output = lock_surface->output->data;
struct diyac_session_lock *lock = wl_container_of(listener, lock, new_surface);
struct wlr_session_lock_surface_v1 *lock_surface = data;
struct diyac_output *output = lock_surface->output->data;
wlr_log(WLR_INFO, "handle_new_surface: New lock surface requested");
assert(output->lock_handle);
output->lock_handle->surface = lock_surface;
output->lock_handle->surface = lock_surface;
wlr_scene_subsurface_tree_create(output->lock_handle->tree, lock_surface->surface);
wlr_scene_subsurface_tree_create(output->lock_handle->tree, lock_surface->surface);
output->lock_handle->surface_destroy.notify = handle_surface_destroy;
wl_signal_add(&lock_surface->events.destroy, &output->lock_handle->surface_destroy);
output->lock_handle->surface_destroy.notify = handle_surface_destroy;
wl_signal_add(&lock_surface->events.destroy, &output->lock_handle->surface_destroy);
output->lock_handle->surface_map.notify = handle_surface_map;
wl_signal_add(&lock_surface->surface->events.map, &output->lock_handle->surface_map);
output->lock_handle->surface_map.notify = handle_surface_map;
wl_signal_add(&lock_surface->surface->events.map, &output->lock_handle->surface_map);
session_lock_update_geometry(output, false);
session_lock_update_geometry(output, false);
}
static void session_lock_destroy(struct diyac_session_lock *lock)
{
struct diyac_output *output;
wl_list_for_each(output, &g_server->outputs, link)
struct diyac_output *output;
wl_list_for_each(output, &g_server->outputs, link)
{
diyac_session_unlock_output(output);
}
if (g_server->lock == lock)
}
if (g_server->lock == lock)
{
g_server->lock = NULL;
}
if (!lock->abandoned)
g_server->lock = NULL;
}
if (!lock->abandoned)
{
wl_list_remove(&lock->destroy.link);
wl_list_remove(&lock->unlock.link);
wl_list_remove(&lock->new_surface.link);
}
free(lock);
wl_list_remove(&lock->destroy.link);
wl_list_remove(&lock->unlock.link);
wl_list_remove(&lock->new_surface.link);
}
wlr_log(WLR_INFO, "session_lock_destroy");
free(lock);
}
static void handle_unlock(struct wl_listener *listener, void *data)
{
struct diyac_session_lock *lock = wl_container_of(listener, lock, unlock);
session_lock_destroy(lock);
diyac_focus_topmost_view(g_server, true);
struct diyac_session_lock *lock = wl_container_of(listener, lock, unlock);
wlr_log(WLR_INFO, "handle_unlock: Lock session is unlocked");
session_lock_destroy(lock);
diyac_focus_topmost_view(g_server, true);
}
static void handle_session_lock_destroy(struct wl_listener *listener, void *data)
{
struct diyac_session_lock *lock = wl_container_of(listener, lock, destroy);
lock->abandoned = true;
wl_list_remove(&lock->destroy.link);
wl_list_remove(&lock->unlock.link);
wl_list_remove(&lock->new_surface.link);
struct diyac_session_lock *lock = wl_container_of(listener, lock, destroy);
lock->abandoned = true;
wlr_log(WLR_INFO, "handle_session_lock_destroy: Lock session is destroyed without unlocking, session abandoned");
wl_list_remove(&lock->destroy.link);
wl_list_remove(&lock->unlock.link);
wl_list_remove(&lock->new_surface.link);
}
static void handle_new_session_lock(struct wl_listener *listener, void *data)
{
struct wlr_session_lock_v1 *lock = data;
if(g_server->lock)
if (g_server->lock)
{
if(g_server->lock->abandoned)
if (g_server->lock->abandoned)
{
session_lock_destroy(g_server->lock);
}
else
{
wlr_log(WLR_ERROR, "session already locked");
wlr_log(WLR_ERROR, "handle_new_session_lock: session already locked");
return;
}
}
struct diyac_session_lock *session = malloc(sizeof(struct diyac_session_lock));
if (!session) {
wlr_log(WLR_ERROR, "session-lock: out of memory");
wlr_session_lock_v1_destroy(lock);
return;
}
if (!session)
{
wlr_log(WLR_ERROR, "handle_new_session_lock: out of memory");
wlr_session_lock_v1_destroy(lock);
return;
}
session->abandoned = false;
session->wlr_session_lock = lock;
session->focused = NULL;
g_server->lock = session;
struct diyac_output *output;
wl_list_for_each(output, &g_server->outputs, link)
wl_list_for_each(output, &g_server->outputs, link)
{
diyac_session_lock_output(output);
}
diyac_session_lock_output(output);
}
session->new_surface.notify = handle_new_surface;
wl_signal_add(&lock->events.new_surface, &session->new_surface);
wl_signal_add(&lock->events.new_surface, &session->new_surface);
session->unlock.notify = handle_unlock;
wl_signal_add(&lock->events.unlock, &session->unlock);
session->unlock.notify = handle_unlock;
wl_signal_add(&lock->events.unlock, &session->unlock);
session->destroy.notify = handle_session_lock_destroy;
wl_signal_add(&lock->events.destroy, &session->destroy);
session->destroy.notify = handle_session_lock_destroy;
wl_signal_add(&lock->events.destroy, &session->destroy);
//session->new_output.notify = handle_new_output;
//wl_signal_add(&server.backend->events.new_output, &session->new_output);
// session->new_output.notify = handle_new_output;
// wl_signal_add(&server.backend->events.new_output, &session->new_output);
wlr_session_lock_v1_send_locked(lock);
wlr_session_lock_v1_send_locked(lock);
}
static void handle_commit(struct wl_listener *listener, void *data)
{
struct wlr_output_event_commit *event = data;
struct diyac_output_lock_handle *handle = wl_container_of(listener, handle, commit);
uint32_t require_reconfigure = WLR_OUTPUT_STATE_MODE
| WLR_OUTPUT_STATE_SCALE | WLR_OUTPUT_STATE_TRANSFORM;
if (event->state->committed & require_reconfigure)
struct wlr_output_event_commit *event = data;
struct diyac_output_lock_handle *handle = wl_container_of(listener, handle, commit);
uint32_t require_reconfigure = WLR_OUTPUT_STATE_MODE | WLR_OUTPUT_STATE_SCALE | WLR_OUTPUT_STATE_TRANSFORM;
if (event->state->committed & require_reconfigure)
{
session_lock_update_geometry(handle->output, false);
}
session_lock_update_geometry(handle->output, false);
}
}
static void handle_lock_manager_destroy(struct wl_listener *listener, void *data)
{
if (g_server->lock)
@ -203,7 +209,7 @@ static void handle_lock_manager_destroy(struct wl_listener *listener, void *data
wl_list_remove(&g_lock_manager_destroy.link);
g_session_lock_manager = NULL;
}
void diyac_init_session_lock(struct diyac_server * server)
void diyac_init_session_lock(struct diyac_server *server)
{
g_session_lock_manager = wlr_session_lock_manager_v1_create(server->wl_display);
@ -216,28 +222,28 @@ void diyac_init_session_lock(struct diyac_server * server)
g_server = server;
}
void diyac_session_lock_output(struct diyac_output * output)
void diyac_session_lock_output(struct diyac_output *output)
{
if(output->lock_handle)
if (output->lock_handle)
{
diyac_session_unlock_output(output);
}
struct diyac_output_lock_handle * handle = malloc(sizeof(struct diyac_output_lock_handle));
if(!handle)
struct diyac_output_lock_handle *handle = malloc(sizeof(struct diyac_output_lock_handle));
if (!handle)
{
wlr_log(WLR_ERROR, "diyac_session_lock_output: out of memory");
exit(EXIT_FAILURE);
}
handle->tree = wlr_scene_tree_create(output->scenes.session);
if(!handle->tree)
if (!handle->tree)
{
free(handle);
wlr_log(WLR_ERROR, "diyac_session_lock_output:Unable to create lock tree");
exit(EXIT_FAILURE);
}
float *black = (float[4]) { 0.f, 0.f, 0.f, 1.f };
handle->background = wlr_scene_rect_create(handle->tree, 0, 0, black);
if(!handle->background)
float *black = (float[4]){0.f, 0.f, 0.f, 1.f};
handle->background = wlr_scene_rect_create(handle->tree, 0, 0, black);
if (!handle->background)
{
free(handle);
wlr_log(WLR_ERROR, "diyac_session_lock_output:Unable to create lock background");
@ -247,21 +253,20 @@ void diyac_session_lock_output(struct diyac_output * output)
handle->surface = NULL;
handle->output = output;
handle->commit.notify = handle_commit;
wl_signal_add(&output->wlr_output->events.commit, &handle->commit);
handle->commit.notify = handle_commit;
wl_signal_add(&output->wlr_output->events.commit, &handle->commit);
output->lock_handle = handle;
session_lock_update_geometry(output, true);
}
void diyac_session_unlock_output(struct diyac_output * output)
void diyac_session_unlock_output(struct diyac_output *output)
{
if(output->lock_handle)
if (output->lock_handle)
{
wlr_scene_node_destroy(&output->lock_handle->tree->node);
if(output->lock_handle->surface)
if (output->lock_handle->surface)
{
wl_list_remove(&output->lock_handle->surface_destroy.link);
wl_list_remove(&output->lock_handle->surface_map.link);

4
view.c
View File

@ -424,6 +424,10 @@ void diyac_view_sync_geo(struct diyac_view *view)
{
struct wlr_box size;
int current_x, current_y, next_x, next_y;
if(!view->mapped)
{
return;
}
wlr_scene_node_coords(&view->scene_tree->node, &current_x, &current_y);
wlr_xdg_surface_get_geometry(view->xdg_surface, &size);

5
xdg.c
View File

@ -208,7 +208,10 @@ static void xdg_toplevel_destroy(struct wl_listener *listener, void *data)
wl_event_source_remove(toplevel->configuration_timeout);
toplevel->configuration_timeout = NULL;
}
wl_list_remove(&toplevel->commit.link);
if(toplevel->mapped)
{
wl_list_remove(&toplevel->commit.link);
}
wl_list_remove(&toplevel->map.link);
wl_list_remove(&toplevel->unmap.link);
wl_list_remove(&toplevel->destroy.link);