improve session lock support stability
This commit is contained in:
parent
5b29514b09
commit
4a7219f03c
195
session.c
195
session.c
@ -8,58 +8,62 @@
|
|||||||
static struct wl_listener g_lock_new;
|
static struct wl_listener g_lock_new;
|
||||||
static struct wl_listener g_lock_manager_destroy;
|
static struct wl_listener g_lock_manager_destroy;
|
||||||
static struct wlr_session_lock_manager_v1 *g_session_lock_manager;
|
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;
|
g_server->lock->focused = NULL;
|
||||||
if(output)
|
if (output)
|
||||||
{
|
{
|
||||||
g_server->lock->focused = output->lock_handle->surface->surface;
|
g_server->lock->focused = output->lock_handle->surface->surface;
|
||||||
}
|
}
|
||||||
diyac_seat_focus_lock_surface(&g_server->seat, g_server->lock->focused);
|
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;
|
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);
|
wlr_scene_rect_set_size(output->lock_handle->background, box.width, box.height);
|
||||||
if (output->lock_handle->surface) {
|
if (output->lock_handle->surface)
|
||||||
wlr_session_lock_surface_v1_configure(output->lock_handle->surface, box.width, box.height);
|
{
|
||||||
}
|
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)
|
static void handle_surface_map(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct diyac_output_lock_handle *handle = wl_container_of(listener, handle, surface_map);
|
struct diyac_output_lock_handle *handle = wl_container_of(listener, handle, surface_map);
|
||||||
if (!g_server->lock->focused)
|
if (!g_server->lock->focused)
|
||||||
{
|
{
|
||||||
focus_output(handle->output);
|
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)
|
static void handle_surface_destroy(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct diyac_output_lock_handle *handle = wl_container_of(listener, handle, surface_destroy);
|
struct diyac_output_lock_handle *handle = wl_container_of(listener, handle, surface_destroy);
|
||||||
|
|
||||||
if(g_server->lock->focused == handle->surface->surface)
|
if (g_server->lock->focused == handle->surface->surface)
|
||||||
{
|
{
|
||||||
struct diyac_output *output;
|
struct diyac_output *output;
|
||||||
wl_list_for_each(output, &g_server->outputs, link)
|
wl_list_for_each(output, &g_server->outputs, link)
|
||||||
{
|
{
|
||||||
if(output == handle->output ||
|
if (output == handle->output ||
|
||||||
!output->lock_handle ||
|
!output->lock_handle ||
|
||||||
!output->lock_handle->surface ||
|
!output->lock_handle->surface ||
|
||||||
!output->lock_handle->surface->surface)
|
!output->lock_handle->surface->surface)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(output->lock_handle->surface->surface->mapped)
|
if (output->lock_handle->surface->surface->mapped)
|
||||||
{
|
{
|
||||||
// focus surface
|
// focus surface
|
||||||
focus_output(output);
|
focus_output(output);
|
||||||
@ -68,130 +72,132 @@ static void handle_surface_destroy(struct wl_listener *listener, void *data)
|
|||||||
}
|
}
|
||||||
focus_output(NULL);
|
focus_output(NULL);
|
||||||
}
|
}
|
||||||
|
wlr_log(WLR_INFO, "handle_surface_destroy: Lock surface destroyed");
|
||||||
assert(handle->surface);
|
assert(handle->surface);
|
||||||
handle->surface = NULL;
|
handle->surface = NULL;
|
||||||
wl_list_remove(&handle->surface_destroy.link);
|
wl_list_remove(&handle->surface_destroy.link);
|
||||||
wl_list_remove(&handle->surface_map.link);
|
wl_list_remove(&handle->surface_map.link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_new_surface(struct wl_listener *listener, void *data)
|
static void handle_new_surface(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct diyac_session_lock *lock = wl_container_of(listener, lock, new_surface);
|
struct diyac_session_lock *lock = wl_container_of(listener, lock, new_surface);
|
||||||
struct wlr_session_lock_surface_v1 *lock_surface = data;
|
struct wlr_session_lock_surface_v1 *lock_surface = data;
|
||||||
struct diyac_output *output = lock_surface->output->data;
|
struct diyac_output *output = lock_surface->output->data;
|
||||||
|
wlr_log(WLR_INFO, "handle_new_surface: New lock surface requested");
|
||||||
assert(output->lock_handle);
|
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;
|
output->lock_handle->surface_destroy.notify = handle_surface_destroy;
|
||||||
wl_signal_add(&lock_surface->events.destroy, &output->lock_handle->surface_destroy);
|
wl_signal_add(&lock_surface->events.destroy, &output->lock_handle->surface_destroy);
|
||||||
|
|
||||||
output->lock_handle->surface_map.notify = 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);
|
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)
|
static void session_lock_destroy(struct diyac_session_lock *lock)
|
||||||
{
|
{
|
||||||
struct diyac_output *output;
|
struct diyac_output *output;
|
||||||
wl_list_for_each(output, &g_server->outputs, link)
|
wl_list_for_each(output, &g_server->outputs, link)
|
||||||
{
|
{
|
||||||
diyac_session_unlock_output(output);
|
diyac_session_unlock_output(output);
|
||||||
}
|
}
|
||||||
if (g_server->lock == lock)
|
if (g_server->lock == lock)
|
||||||
{
|
{
|
||||||
g_server->lock = NULL;
|
g_server->lock = NULL;
|
||||||
}
|
}
|
||||||
if (!lock->abandoned)
|
if (!lock->abandoned)
|
||||||
{
|
{
|
||||||
wl_list_remove(&lock->destroy.link);
|
wl_list_remove(&lock->destroy.link);
|
||||||
wl_list_remove(&lock->unlock.link);
|
wl_list_remove(&lock->unlock.link);
|
||||||
wl_list_remove(&lock->new_surface.link);
|
wl_list_remove(&lock->new_surface.link);
|
||||||
}
|
}
|
||||||
free(lock);
|
wlr_log(WLR_INFO, "session_lock_destroy");
|
||||||
|
free(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_unlock(struct wl_listener *listener, void *data)
|
static void handle_unlock(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct diyac_session_lock *lock = wl_container_of(listener, lock, unlock);
|
struct diyac_session_lock *lock = wl_container_of(listener, lock, unlock);
|
||||||
session_lock_destroy(lock);
|
wlr_log(WLR_INFO, "handle_unlock: Lock session is unlocked");
|
||||||
diyac_focus_topmost_view(g_server, true);
|
session_lock_destroy(lock);
|
||||||
|
diyac_focus_topmost_view(g_server, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_session_lock_destroy(struct wl_listener *listener, void *data)
|
static void handle_session_lock_destroy(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct diyac_session_lock *lock = wl_container_of(listener, lock, destroy);
|
struct diyac_session_lock *lock = wl_container_of(listener, lock, destroy);
|
||||||
lock->abandoned = true;
|
lock->abandoned = true;
|
||||||
wl_list_remove(&lock->destroy.link);
|
wlr_log(WLR_INFO, "handle_session_lock_destroy: Lock session is destroyed without unlocking, session abandoned");
|
||||||
wl_list_remove(&lock->unlock.link);
|
wl_list_remove(&lock->destroy.link);
|
||||||
wl_list_remove(&lock->new_surface.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)
|
static void handle_new_session_lock(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct wlr_session_lock_v1 *lock = 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);
|
session_lock_destroy(g_server->lock);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wlr_log(WLR_ERROR, "session already locked");
|
wlr_log(WLR_ERROR, "handle_new_session_lock: session already locked");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
struct diyac_session_lock *session = malloc(sizeof(struct diyac_session_lock));
|
struct diyac_session_lock *session = malloc(sizeof(struct diyac_session_lock));
|
||||||
if (!session) {
|
if (!session)
|
||||||
wlr_log(WLR_ERROR, "session-lock: out of memory");
|
{
|
||||||
wlr_session_lock_v1_destroy(lock);
|
wlr_log(WLR_ERROR, "handle_new_session_lock: out of memory");
|
||||||
return;
|
wlr_session_lock_v1_destroy(lock);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
session->abandoned = false;
|
session->abandoned = false;
|
||||||
session->wlr_session_lock = lock;
|
session->wlr_session_lock = lock;
|
||||||
session->focused = NULL;
|
session->focused = NULL;
|
||||||
g_server->lock = session;
|
g_server->lock = session;
|
||||||
|
|
||||||
struct diyac_output *output;
|
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;
|
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;
|
session->unlock.notify = handle_unlock;
|
||||||
wl_signal_add(&lock->events.unlock, &session->unlock);
|
wl_signal_add(&lock->events.unlock, &session->unlock);
|
||||||
|
|
||||||
session->destroy.notify = handle_session_lock_destroy;
|
session->destroy.notify = handle_session_lock_destroy;
|
||||||
wl_signal_add(&lock->events.destroy, &session->destroy);
|
wl_signal_add(&lock->events.destroy, &session->destroy);
|
||||||
|
|
||||||
//session->new_output.notify = handle_new_output;
|
// session->new_output.notify = handle_new_output;
|
||||||
//wl_signal_add(&server.backend->events.new_output, &session->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)
|
static void handle_commit(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
struct wlr_output_event_commit *event = data;
|
struct wlr_output_event_commit *event = data;
|
||||||
struct diyac_output_lock_handle *handle = wl_container_of(listener, handle, commit);
|
struct diyac_output_lock_handle *handle = wl_container_of(listener, handle, commit);
|
||||||
uint32_t require_reconfigure = WLR_OUTPUT_STATE_MODE
|
uint32_t require_reconfigure = WLR_OUTPUT_STATE_MODE | WLR_OUTPUT_STATE_SCALE | WLR_OUTPUT_STATE_TRANSFORM;
|
||||||
| WLR_OUTPUT_STATE_SCALE | WLR_OUTPUT_STATE_TRANSFORM;
|
if (event->state->committed & require_reconfigure)
|
||||||
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)
|
static void handle_lock_manager_destroy(struct wl_listener *listener, void *data)
|
||||||
{
|
{
|
||||||
if (g_server->lock)
|
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);
|
wl_list_remove(&g_lock_manager_destroy.link);
|
||||||
g_session_lock_manager = NULL;
|
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);
|
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;
|
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);
|
diyac_session_unlock_output(output);
|
||||||
}
|
}
|
||||||
struct diyac_output_lock_handle * handle = malloc(sizeof(struct diyac_output_lock_handle));
|
struct diyac_output_lock_handle *handle = malloc(sizeof(struct diyac_output_lock_handle));
|
||||||
if(!handle)
|
if (!handle)
|
||||||
{
|
{
|
||||||
wlr_log(WLR_ERROR, "diyac_session_lock_output: out of memory");
|
wlr_log(WLR_ERROR, "diyac_session_lock_output: out of memory");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
handle->tree = wlr_scene_tree_create(output->scenes.session);
|
handle->tree = wlr_scene_tree_create(output->scenes.session);
|
||||||
if(!handle->tree)
|
if (!handle->tree)
|
||||||
{
|
{
|
||||||
free(handle);
|
free(handle);
|
||||||
wlr_log(WLR_ERROR, "diyac_session_lock_output:Unable to create lock tree");
|
wlr_log(WLR_ERROR, "diyac_session_lock_output:Unable to create lock tree");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
float *black = (float[4]) { 0.f, 0.f, 0.f, 1.f };
|
float *black = (float[4]){0.f, 0.f, 0.f, 1.f};
|
||||||
handle->background = wlr_scene_rect_create(handle->tree, 0, 0, black);
|
handle->background = wlr_scene_rect_create(handle->tree, 0, 0, black);
|
||||||
if(!handle->background)
|
if (!handle->background)
|
||||||
{
|
{
|
||||||
free(handle);
|
free(handle);
|
||||||
wlr_log(WLR_ERROR, "diyac_session_lock_output:Unable to create lock background");
|
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->surface = NULL;
|
||||||
handle->output = output;
|
handle->output = output;
|
||||||
|
|
||||||
handle->commit.notify = handle_commit;
|
handle->commit.notify = handle_commit;
|
||||||
wl_signal_add(&output->wlr_output->events.commit, &handle->commit);
|
wl_signal_add(&output->wlr_output->events.commit, &handle->commit);
|
||||||
|
|
||||||
output->lock_handle = handle;
|
output->lock_handle = handle;
|
||||||
|
|
||||||
session_lock_update_geometry(output, true);
|
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);
|
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_destroy.link);
|
||||||
wl_list_remove(&output->lock_handle->surface_map.link);
|
wl_list_remove(&output->lock_handle->surface_map.link);
|
||||||
|
4
view.c
4
view.c
@ -424,6 +424,10 @@ void diyac_view_sync_geo(struct diyac_view *view)
|
|||||||
{
|
{
|
||||||
struct wlr_box size;
|
struct wlr_box size;
|
||||||
int current_x, current_y, next_x, next_y;
|
int current_x, current_y, next_x, next_y;
|
||||||
|
if(!view->mapped)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
wlr_scene_node_coords(&view->scene_tree->node, ¤t_x, ¤t_y);
|
wlr_scene_node_coords(&view->scene_tree->node, ¤t_x, ¤t_y);
|
||||||
wlr_xdg_surface_get_geometry(view->xdg_surface, &size);
|
wlr_xdg_surface_get_geometry(view->xdg_surface, &size);
|
||||||
|
|
||||||
|
5
xdg.c
5
xdg.c
@ -208,7 +208,10 @@ static void xdg_toplevel_destroy(struct wl_listener *listener, void *data)
|
|||||||
wl_event_source_remove(toplevel->configuration_timeout);
|
wl_event_source_remove(toplevel->configuration_timeout);
|
||||||
toplevel->configuration_timeout = NULL;
|
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->map.link);
|
||||||
wl_list_remove(&toplevel->unmap.link);
|
wl_list_remove(&toplevel->unmap.link);
|
||||||
wl_list_remove(&toplevel->destroy.link);
|
wl_list_remove(&toplevel->destroy.link);
|
||||||
|
Loading…
Reference in New Issue
Block a user