wlr_ext_workspaces: honor activate from client + format

This commit is contained in:
vaxerski 2023-05-22 19:36:47 +02:00
parent ad244190e0
commit 086f724951
4 changed files with 473 additions and 539 deletions

View file

@ -1486,6 +1486,15 @@ CWorkspace* CCompositor::getWorkspaceByString(const std::string& str) {
return nullptr; return nullptr;
} }
CWorkspace* CCompositor::getWorkspaceByWorkspaceHandle(const wlr_ext_workspace_handle_v1* handle) {
for (auto& ws : m_vWorkspaces) {
if (ws->m_pWlrHandle == handle)
return ws.get();
}
return nullptr;
}
bool CCompositor::isPointOnAnyMonitor(const Vector2D& point) { bool CCompositor::isPointOnAnyMonitor(const Vector2D& point) {
for (auto& m : m_vMonitors) { for (auto& m : m_vMonitors) {
if (VECINRECT(point, m->vecPosition.x, m->vecPosition.y, m->vecSize.x + m->vecPosition.x, m->vecSize.y + m->vecPosition.y)) if (VECINRECT(point, m->vecPosition.x, m->vecPosition.y, m->vecSize.x + m->vecPosition.x, m->vecSize.y + m->vecPosition.y))

View file

@ -144,6 +144,7 @@ class CCompositor {
CWorkspace* getWorkspaceByID(const int&); CWorkspace* getWorkspaceByID(const int&);
CWorkspace* getWorkspaceByName(const std::string&); CWorkspace* getWorkspaceByName(const std::string&);
CWorkspace* getWorkspaceByString(const std::string&); CWorkspace* getWorkspaceByString(const std::string&);
CWorkspace* getWorkspaceByWorkspaceHandle(const wlr_ext_workspace_handle_v1*);
void sanityCheckWorkspaces(); void sanityCheckWorkspaces();
void updateWorkspaceWindowDecos(const int&); void updateWorkspaceWindowDecos(const int&);
int getWindowsOnWorkspace(const int&); int getWindowsOnWorkspace(const int&);

View file

@ -8,32 +8,27 @@
#include "wlr_ext_workspace_v1.hpp" #include "wlr_ext_workspace_v1.hpp"
#include <wlr/types/wlr_seat.h> #include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "../Compositor.hpp"
#define WORKSPACE_V1_VERSION 1 #define WORKSPACE_V1_VERSION 1
static void workspace_handle_destroy(struct wl_client *client, static void workspace_handle_destroy(struct wl_client* client, struct wl_resource* resource);
struct wl_resource *resource) ;
static void workspace_handle_activate(struct wl_client *client, static void workspace_handle_activate(struct wl_client* client, struct wl_resource* resource);
struct wl_resource *resource) ;
static void workspace_handle_deactivate(struct wl_client *client, static void workspace_handle_deactivate(struct wl_client* client, struct wl_resource* resource);
struct wl_resource *resource) ;
static void workspace_handle_remove(struct wl_client *client, static void workspace_handle_remove(struct wl_client* client, struct wl_resource* resource);
struct wl_resource *resource) ;
static void workspace_group_handle_handle_create_workspace(struct wl_client *client, static void workspace_group_handle_handle_create_workspace(struct wl_client* client, struct wl_resource* resource, const char* arg);
struct wl_resource *resource, const char *arg) ;
static void workspace_group_handle_handle_destroy(struct wl_client *client, static void workspace_group_handle_handle_destroy(struct wl_client* client, struct wl_resource* resource);
struct wl_resource *resource) ;
static void workspace_manager_commit(struct wl_client *client, static void workspace_manager_commit(struct wl_client* client, struct wl_resource* resource);
struct wl_resource *resource) ;
static void workspace_manager_stop(struct wl_client *client, static void workspace_manager_stop(struct wl_client* client, struct wl_resource* resource);
struct wl_resource *resource) ;
//
inline static struct zext_workspace_handle_v1_interface workspace_handle_impl = { inline static struct zext_workspace_handle_v1_interface workspace_handle_impl = {
.destroy = workspace_handle_destroy, .destroy = workspace_handle_destroy,
@ -62,49 +57,39 @@ static void workspace_manager_idle_send_done(void *data) {
manager->idle_source = NULL; manager->idle_source = NULL;
} }
static void workspace_manager_update_idle_source( static void workspace_manager_update_idle_source(struct wlr_ext_workspace_manager_v1* manager) {
struct wlr_ext_workspace_manager_v1 *manager) {
if (manager->idle_source) { if (manager->idle_source) {
return; return;
} }
manager->idle_source = wl_event_loop_add_idle(manager->event_loop, manager->idle_source = wl_event_loop_add_idle(manager->event_loop, workspace_manager_idle_send_done, manager);
workspace_manager_idle_send_done, manager);
} }
static struct wlr_ext_workspace_handle_v1 *workspace_from_resource( static struct wlr_ext_workspace_handle_v1* workspace_from_resource(struct wl_resource* resource) {
struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &zext_workspace_handle_v1_interface, &workspace_handle_impl));
assert(wl_resource_instance_of(resource,
&zext_workspace_handle_v1_interface,
&workspace_handle_impl));
return (wlr_ext_workspace_handle_v1*)wl_resource_get_user_data(resource); return (wlr_ext_workspace_handle_v1*)wl_resource_get_user_data(resource);
} }
static struct wlr_ext_workspace_group_handle_v1 *workspace_group_from_resource( static struct wlr_ext_workspace_group_handle_v1* workspace_group_from_resource(struct wl_resource* resource) {
struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &zext_workspace_group_handle_v1_interface, &workspace_group_impl));
assert(wl_resource_instance_of(resource,
&zext_workspace_group_handle_v1_interface,
&workspace_group_impl));
return (wlr_ext_workspace_group_handle_v1*)wl_resource_get_user_data(resource); return (wlr_ext_workspace_group_handle_v1*)wl_resource_get_user_data(resource);
} }
static void workspace_handle_destroy(struct wl_client *client, static void workspace_handle_destroy(struct wl_client* client, struct wl_resource* resource) {
struct wl_resource *resource) {
wl_resource_destroy(resource); wl_resource_destroy(resource);
} }
static void workspace_handle_activate(struct wl_client *client, static void workspace_handle_activate(struct wl_client* client, struct wl_resource* resource) {
struct wl_resource *resource) {
struct wlr_ext_workspace_handle_v1* workspace = workspace_from_resource(resource); struct wlr_ext_workspace_handle_v1* workspace = workspace_from_resource(resource);
if (!workspace) { if (!workspace) {
return; return;
} }
workspace->pending |= WLR_EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE; workspace->pending |= WLR_EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE;
workspace->requestsActivate = true;
} }
static void workspace_handle_remove(struct wl_client *client, static void workspace_handle_remove(struct wl_client* client, struct wl_resource* resource) {
struct wl_resource *resource) {
struct wlr_ext_workspace_handle_v1* workspace = workspace_from_resource(resource); struct wlr_ext_workspace_handle_v1* workspace = workspace_from_resource(resource);
if (!workspace) { if (!workspace) {
return; return;
@ -113,8 +98,7 @@ static void workspace_handle_remove(struct wl_client *client,
wl_signal_emit_mutable(&workspace->events.remove_request, NULL); wl_signal_emit_mutable(&workspace->events.remove_request, NULL);
} }
static void workspace_handle_deactivate(struct wl_client *client, static void workspace_handle_deactivate(struct wl_client* client, struct wl_resource* resource) {
struct wl_resource *resource) {
struct wlr_ext_workspace_handle_v1* workspace = workspace_from_resource(resource); struct wlr_ext_workspace_handle_v1* workspace = workspace_from_resource(resource);
if (!workspace) { if (!workspace) {
return; return;
@ -136,33 +120,27 @@ static bool push_entry_in_array(struct wl_array *array, uint32_t entry) {
return true; return true;
} }
static bool fill_array_from_workspace_state(struct wl_array *array, static bool fill_array_from_workspace_state(struct wl_array* array, uint32_t state) {
uint32_t state) { if ((state & WLR_EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE) && !push_entry_in_array(array, ZEXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE)) {
if ((state & WLR_EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE) &&
!push_entry_in_array(array, ZEXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE)) {
return false; return false;
} }
if ((state & WLR_EXT_WORKSPACE_HANDLE_V1_STATE_URGENT) && if ((state & WLR_EXT_WORKSPACE_HANDLE_V1_STATE_URGENT) && !push_entry_in_array(array, ZEXT_WORKSPACE_HANDLE_V1_STATE_URGENT)) {
!push_entry_in_array(array, ZEXT_WORKSPACE_HANDLE_V1_STATE_URGENT)) {
return false; return false;
} }
if ((state & WLR_EXT_WORKSPACE_HANDLE_V1_STATE_HIDDEN) && if ((state & WLR_EXT_WORKSPACE_HANDLE_V1_STATE_HIDDEN) && !push_entry_in_array(array, ZEXT_WORKSPACE_HANDLE_V1_STATE_HIDDEN)) {
!push_entry_in_array(array, ZEXT_WORKSPACE_HANDLE_V1_STATE_HIDDEN)) {
return false; return false;
} }
return true; return true;
} }
static void workspace_handle_send_details_to_resource( static void workspace_handle_send_details_to_resource(struct wlr_ext_workspace_handle_v1* workspace, struct wl_resource* resource) {
struct wlr_ext_workspace_handle_v1 *workspace, struct wl_resource *resource) {
if (workspace->name) { if (workspace->name) {
zext_workspace_handle_v1_send_name(resource, workspace->name); zext_workspace_handle_v1_send_name(resource, workspace->name);
} }
if (workspace->coordinates.size > 0) { if (workspace->coordinates.size > 0) {
zext_workspace_handle_v1_send_coordinates(resource, zext_workspace_handle_v1_send_coordinates(resource, &workspace->coordinates);
&workspace->coordinates);
} }
struct wl_array state; struct wl_array state;
@ -176,10 +154,7 @@ static void workspace_handle_send_details_to_resource(
zext_workspace_handle_v1_send_state(resource, &state); zext_workspace_handle_v1_send_state(resource, &state);
} }
void wlr_ext_workspace_handle_v1_set_name(struct wlr_ext_workspace_handle_v1* workspace, const char* name) {
void wlr_ext_workspace_handle_v1_set_name(struct wlr_ext_workspace_handle_v1 *workspace,
const char* name) {
free(workspace->name); free(workspace->name);
workspace->name = strdup(name); workspace->name = strdup(name);
@ -191,8 +166,7 @@ void wlr_ext_workspace_handle_v1_set_name(struct wlr_ext_workspace_handle_v1 *wo
workspace_manager_update_idle_source(workspace->group->manager); workspace_manager_update_idle_source(workspace->group->manager);
} }
void wlr_ext_workspace_handle_v1_set_coordinates( void wlr_ext_workspace_handle_v1_set_coordinates(struct wlr_ext_workspace_handle_v1* workspace, struct wl_array* coordinates) {
struct wlr_ext_workspace_handle_v1 *workspace, struct wl_array *coordinates) {
wl_array_copy(&workspace->coordinates, coordinates); wl_array_copy(&workspace->coordinates, coordinates);
struct wl_resource *tmp, *resource; struct wl_resource *tmp, *resource;
@ -226,8 +200,7 @@ static void workspace_send_state(struct wlr_ext_workspace_handle_v1 *workspace)
workspace_manager_update_idle_source(workspace->group->manager); workspace_manager_update_idle_source(workspace->group->manager);
} }
void wlr_ext_workspace_handle_v1_set_active( void wlr_ext_workspace_handle_v1_set_active(struct wlr_ext_workspace_handle_v1* workspace, bool activate) {
struct wlr_ext_workspace_handle_v1 *workspace, bool activate) {
if (activate) { if (activate) {
workspace->server_state |= WLR_EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE; workspace->server_state |= WLR_EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE;
} else { } else {
@ -237,8 +210,7 @@ void wlr_ext_workspace_handle_v1_set_active(
workspace_send_state(workspace); workspace_send_state(workspace);
} }
void wlr_ext_workspace_handle_v1_set_urgent( void wlr_ext_workspace_handle_v1_set_urgent(struct wlr_ext_workspace_handle_v1* workspace, bool urgent) {
struct wlr_ext_workspace_handle_v1 *workspace, bool urgent) {
if (urgent) { if (urgent) {
workspace->server_state |= WLR_EXT_WORKSPACE_HANDLE_V1_STATE_URGENT; workspace->server_state |= WLR_EXT_WORKSPACE_HANDLE_V1_STATE_URGENT;
} else { } else {
@ -248,8 +220,7 @@ void wlr_ext_workspace_handle_v1_set_urgent(
workspace_send_state(workspace); workspace_send_state(workspace);
} }
void wlr_ext_workspace_handle_v1_set_hidden( void wlr_ext_workspace_handle_v1_set_hidden(struct wlr_ext_workspace_handle_v1* workspace, bool hidden) {
struct wlr_ext_workspace_handle_v1 *workspace, bool hidden) {
if (hidden) { if (hidden) {
workspace->server_state |= WLR_EXT_WORKSPACE_HANDLE_V1_STATE_HIDDEN; workspace->server_state |= WLR_EXT_WORKSPACE_HANDLE_V1_STATE_HIDDEN;
} else { } else {
@ -259,21 +230,16 @@ void wlr_ext_workspace_handle_v1_set_hidden(
workspace_send_state(workspace); workspace_send_state(workspace);
} }
static struct wl_resource *create_workspace_resource_for_group_resource( static struct wl_resource* create_workspace_resource_for_group_resource(struct wlr_ext_workspace_handle_v1* workspace, struct wl_resource* group_resource) {
struct wlr_ext_workspace_handle_v1 *workspace,
struct wl_resource *group_resource) {
struct wl_client* client = wl_resource_get_client(group_resource); struct wl_client* client = wl_resource_get_client(group_resource);
struct wl_resource *resource = wl_resource_create(client, struct wl_resource* resource = wl_resource_create(client, &zext_workspace_handle_v1_interface, wl_resource_get_version(group_resource), 0);
&zext_workspace_handle_v1_interface,
wl_resource_get_version(group_resource), 0);
if (!resource) { if (!resource) {
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
return NULL; return NULL;
} }
wl_resource_set_implementation(resource, &workspace_handle_impl, workspace, wl_resource_set_implementation(resource, &workspace_handle_impl, workspace, workspace_handle_resource_destroy);
workspace_handle_resource_destroy);
wl_list_insert(&workspace->resources, wl_resource_get_link(resource)); wl_list_insert(&workspace->resources, wl_resource_get_link(resource));
zext_workspace_group_handle_v1_send_workspace(group_resource, resource); zext_workspace_group_handle_v1_send_workspace(group_resource, resource);
@ -281,10 +247,8 @@ static struct wl_resource *create_workspace_resource_for_group_resource(
return resource; return resource;
} }
struct wlr_ext_workspace_handle_v1 *wlr_ext_workspace_handle_v1_create( struct wlr_ext_workspace_handle_v1* wlr_ext_workspace_handle_v1_create(struct wlr_ext_workspace_group_handle_v1* group) {
struct wlr_ext_workspace_group_handle_v1 *group) { struct wlr_ext_workspace_handle_v1* workspace = (wlr_ext_workspace_handle_v1*)calloc(1, sizeof(struct wlr_ext_workspace_handle_v1));
struct wlr_ext_workspace_handle_v1 *workspace = (wlr_ext_workspace_handle_v1 *)calloc(1,
sizeof(struct wlr_ext_workspace_handle_v1));
if (!workspace) { if (!workspace) {
return NULL; return NULL;
} }
@ -304,8 +268,7 @@ struct wlr_ext_workspace_handle_v1 *wlr_ext_workspace_handle_v1_create(
return workspace; return workspace;
} }
void wlr_ext_workspace_handle_v1_destroy( void wlr_ext_workspace_handle_v1_destroy(struct wlr_ext_workspace_handle_v1* workspace) {
struct wlr_ext_workspace_handle_v1 *workspace) {
if (!workspace) { if (!workspace) {
return; return;
} }
@ -328,10 +291,8 @@ void wlr_ext_workspace_handle_v1_destroy(
free(workspace->name); free(workspace->name);
} }
static void workspace_group_handle_handle_create_workspace(struct wl_client *client, static void workspace_group_handle_handle_create_workspace(struct wl_client* client, struct wl_resource* resource, const char* arg) {
struct wl_resource *resource, const char *arg) { struct wlr_ext_workspace_group_handle_v1* group = workspace_group_from_resource(resource);
struct wlr_ext_workspace_group_handle_v1 *group =
workspace_group_from_resource(resource);
struct wlr_ext_workspace_group_handle_v1_create_workspace_event event; struct wlr_ext_workspace_group_handle_v1_create_workspace_event event;
event.workspace_group = group; event.workspace_group = group;
@ -339,8 +300,7 @@ static void workspace_group_handle_handle_create_workspace(struct wl_client *cli
wl_signal_emit_mutable(&group->events.create_workspace_request, &event); wl_signal_emit_mutable(&group->events.create_workspace_request, &event);
} }
static void workspace_group_handle_handle_destroy(struct wl_client *client, static void workspace_group_handle_handle_destroy(struct wl_client* client, struct wl_resource* resource) {
struct wl_resource *resource) {
wl_resource_destroy(resource); wl_resource_destroy(resource);
} }
@ -351,88 +311,71 @@ static void workspace_group_resource_destroy(struct wl_resource *resource) {
/** /**
* Create the workspace group resource and child workspace resources as well. * Create the workspace group resource and child workspace resources as well.
*/ */
static struct wl_resource *create_workspace_group_resource_for_resource( static struct wl_resource* create_workspace_group_resource_for_resource(struct wlr_ext_workspace_group_handle_v1* group, struct wl_resource* manager_resource) {
struct wlr_ext_workspace_group_handle_v1 *group,
struct wl_resource *manager_resource) {
struct wl_client* client = wl_resource_get_client(manager_resource); struct wl_client* client = wl_resource_get_client(manager_resource);
struct wl_resource *resource = wl_resource_create(client, struct wl_resource* resource = wl_resource_create(client, &zext_workspace_group_handle_v1_interface, wl_resource_get_version(manager_resource), 0);
&zext_workspace_group_handle_v1_interface,
wl_resource_get_version(manager_resource), 0);
if (!resource) { if (!resource) {
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
return NULL; return NULL;
} }
wl_resource_set_implementation(resource, &workspace_group_impl, group, wl_resource_set_implementation(resource, &workspace_group_impl, group, workspace_group_resource_destroy);
workspace_group_resource_destroy);
wl_list_insert(&group->resources, wl_resource_get_link(resource)); wl_list_insert(&group->resources, wl_resource_get_link(resource));
zext_workspace_manager_v1_send_workspace_group(manager_resource, resource); zext_workspace_manager_v1_send_workspace_group(manager_resource, resource);
struct wlr_ext_workspace_handle_v1 *tmp, *workspace; struct wlr_ext_workspace_handle_v1 *tmp, *workspace;
wl_list_for_each_safe(workspace, tmp, &group->workspaces, link) { wl_list_for_each_safe(workspace, tmp, &group->workspaces, link) {
struct wl_resource *workspace_resource = struct wl_resource* workspace_resource = create_workspace_resource_for_group_resource(workspace, resource);
create_workspace_resource_for_group_resource(workspace, resource);
workspace_handle_send_details_to_resource(workspace, workspace_resource); workspace_handle_send_details_to_resource(workspace, workspace_resource);
} }
return resource; return resource;
} }
static void send_output_to_group_resource(struct wl_resource *group_resource, static void send_output_to_group_resource(struct wl_resource* group_resource, struct wlr_output* output, bool enter) {
struct wlr_output *output, bool enter) {
struct wl_client* client = wl_resource_get_client(group_resource); struct wl_client* client = wl_resource_get_client(group_resource);
struct wl_resource *output_resource, *tmp; struct wl_resource *output_resource, *tmp;
wl_resource_for_each_safe(output_resource, tmp, &output->resources) { wl_resource_for_each_safe(output_resource, tmp, &output->resources) {
if (wl_resource_get_client(output_resource) == client) { if (wl_resource_get_client(output_resource) == client) {
if (enter) { if (enter) {
zext_workspace_group_handle_v1_send_output_enter(group_resource, zext_workspace_group_handle_v1_send_output_enter(group_resource, output_resource);
output_resource);
} else { } else {
zext_workspace_group_handle_v1_send_output_leave(group_resource, zext_workspace_group_handle_v1_send_output_leave(group_resource, output_resource);
output_resource);
} }
} }
} }
} }
static void group_send_output(struct wlr_ext_workspace_group_handle_v1 *group, static void group_send_output(struct wlr_ext_workspace_group_handle_v1* group, struct wlr_output* output, bool enter) {
struct wlr_output *output, bool enter) {
struct wl_resource *resource, *tmp; struct wl_resource *resource, *tmp;
wl_resource_for_each_safe(resource, tmp, &group->resources) { wl_resource_for_each_safe(resource, tmp, &group->resources) {
send_output_to_group_resource(resource, output, enter); send_output_to_group_resource(resource, output, enter);
} }
} }
static void workspace_handle_output_bind(struct wl_listener *listener, static void workspace_handle_output_bind(struct wl_listener* listener, void* data) {
void *data) {
struct wlr_output_event_bind* evt = (wlr_output_event_bind*)data; struct wlr_output_event_bind* evt = (wlr_output_event_bind*)data;
struct wlr_ext_workspace_group_handle_v1_output *output = struct wlr_ext_workspace_group_handle_v1_output* output = wl_container_of(listener, output, output_bind);
wl_container_of(listener, output, output_bind);
struct wl_client* client = wl_resource_get_client(evt->resource); struct wl_client* client = wl_resource_get_client(evt->resource);
struct wl_resource * group_resource, *tmp; struct wl_resource * group_resource, *tmp;
wl_resource_for_each_safe(group_resource, tmp, &output->group_handle->resources) { wl_resource_for_each_safe(group_resource, tmp, &output->group_handle->resources) {
if (client == wl_resource_get_client(group_resource)) { if (client == wl_resource_get_client(group_resource)) {
zext_workspace_group_handle_v1_send_output_enter(group_resource, zext_workspace_group_handle_v1_send_output_enter(group_resource, evt->resource);
evt->resource);
} }
} }
workspace_manager_update_idle_source(output->group_handle->manager); workspace_manager_update_idle_source(output->group_handle->manager);
} }
static void workspace_handle_output_destroy(struct wl_listener *listener, static void workspace_handle_output_destroy(struct wl_listener* listener, void* data) {
void *data) { struct wlr_ext_workspace_group_handle_v1_output* output = wl_container_of(listener, output, output_destroy);
struct wlr_ext_workspace_group_handle_v1_output *output = wlr_ext_workspace_group_handle_v1_output_leave(output->group_handle, output->output);
wl_container_of(listener, output, output_destroy);
wlr_ext_workspace_group_handle_v1_output_leave(output->group_handle,
output->output);
} }
void wlr_ext_workspace_group_handle_v1_output_enter( void wlr_ext_workspace_group_handle_v1_output_enter(struct wlr_ext_workspace_group_handle_v1* group, struct wlr_output* output) {
struct wlr_ext_workspace_group_handle_v1 *group, struct wlr_output *output) {
struct wlr_ext_workspace_group_handle_v1_output* group_output; struct wlr_ext_workspace_group_handle_v1_output* group_output;
wl_list_for_each(group_output, &group->outputs, link) { wl_list_for_each(group_output, &group->outputs, link) {
if (group_output->output == output) { if (group_output->output == output) {
@ -459,15 +402,13 @@ void wlr_ext_workspace_group_handle_v1_output_enter(
group_send_output(group, output, true); group_send_output(group, output, true);
} }
static void group_output_destroy( static void group_output_destroy(struct wlr_ext_workspace_group_handle_v1_output* output) {
struct wlr_ext_workspace_group_handle_v1_output *output) {
wl_list_remove(&output->link); wl_list_remove(&output->link);
wl_list_remove(&output->output_destroy.link); wl_list_remove(&output->output_destroy.link);
free(output); free(output);
} }
void wlr_ext_workspace_group_handle_v1_output_leave( void wlr_ext_workspace_group_handle_v1_output_leave(struct wlr_ext_workspace_group_handle_v1* group, struct wlr_output* output) {
struct wlr_ext_workspace_group_handle_v1 *group, struct wlr_output *output) {
struct wlr_ext_workspace_group_handle_v1_output* group_output_iterator; struct wlr_ext_workspace_group_handle_v1_output* group_output_iterator;
struct wlr_ext_workspace_group_handle_v1_output* group_output = NULL; struct wlr_ext_workspace_group_handle_v1_output* group_output = NULL;
@ -486,20 +427,16 @@ void wlr_ext_workspace_group_handle_v1_output_leave(
} }
} }
static void group_send_details_to_resource( static void group_send_details_to_resource(struct wlr_ext_workspace_group_handle_v1* group, struct wl_resource* resource) {
struct wlr_ext_workspace_group_handle_v1 *group,
struct wl_resource *resource) {
struct wlr_ext_workspace_group_handle_v1_output* output; struct wlr_ext_workspace_group_handle_v1_output* output;
wl_list_for_each(output, &group->outputs, link) { wl_list_for_each(output, &group->outputs, link) {
send_output_to_group_resource(resource, output->output, true); send_output_to_group_resource(resource, output->output, true);
} }
} }
struct wlr_ext_workspace_group_handle_v1 *wlr_ext_workspace_group_handle_v1_create( struct wlr_ext_workspace_group_handle_v1* wlr_ext_workspace_group_handle_v1_create(struct wlr_ext_workspace_manager_v1* manager) {
struct wlr_ext_workspace_manager_v1 *manager) {
struct wlr_ext_workspace_group_handle_v1 *group = (wlr_ext_workspace_group_handle_v1 *)calloc(1, struct wlr_ext_workspace_group_handle_v1* group = (wlr_ext_workspace_group_handle_v1*)calloc(1, sizeof(struct wlr_ext_workspace_group_handle_v1));
sizeof(struct wlr_ext_workspace_group_handle_v1));
if (!group) { if (!group) {
return NULL; return NULL;
} }
@ -521,8 +458,7 @@ struct wlr_ext_workspace_group_handle_v1 *wlr_ext_workspace_group_handle_v1_crea
return group; return group;
} }
void wlr_ext_workspace_group_handle_v1_destroy( void wlr_ext_workspace_group_handle_v1_destroy(struct wlr_ext_workspace_group_handle_v1* group) {
struct wlr_ext_workspace_group_handle_v1 *group) {
if (!group) { if (!group) {
return; return;
} }
@ -552,34 +488,43 @@ void wlr_ext_workspace_group_handle_v1_destroy(
free(group); free(group);
} }
static struct wlr_ext_workspace_manager_v1 *manager_from_resource( static struct wlr_ext_workspace_manager_v1* manager_from_resource(struct wl_resource* resource) {
struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &zext_workspace_manager_v1_interface, &workspace_manager_impl));
assert(wl_resource_instance_of(resource,
&zext_workspace_manager_v1_interface,
&workspace_manager_impl));
return (wlr_ext_workspace_manager_v1*)wl_resource_get_user_data(resource); return (wlr_ext_workspace_manager_v1*)wl_resource_get_user_data(resource);
} }
static void workspace_manager_commit(struct wl_client *client, static void workspace_manager_commit(struct wl_client* client, struct wl_resource* resource) {
struct wl_resource *resource) {
struct wlr_ext_workspace_manager_v1* manager = manager_from_resource(resource); struct wlr_ext_workspace_manager_v1* manager = manager_from_resource(resource);
if (!manager) { if (!manager) {
return; return;
} }
std::vector<CWorkspace*> toSwitchTo;
struct wlr_ext_workspace_group_handle_v1* group; struct wlr_ext_workspace_group_handle_v1* group;
struct wlr_ext_workspace_handle_v1* workspace; struct wlr_ext_workspace_handle_v1* workspace;
wl_list_for_each(group, &manager->groups, link) { wl_list_for_each(group, &manager->groups, link) {
wl_list_for_each(workspace, &group->workspaces, link) { wl_list_for_each(workspace, &group->workspaces, link) {
if (workspace->requestsActivate) {
const auto PWORKSPACE = g_pCompositor->getWorkspaceByWorkspaceHandle(workspace);
if (PWORKSPACE)
toSwitchTo.push_back(PWORKSPACE);
workspace->requestsActivate = false;
}
workspace->current = workspace->pending; workspace->current = workspace->pending;
} }
} }
for (auto& ws : toSwitchTo)
g_pCompositor->getMonitorFromID(ws->m_iMonitorID)->changeWorkspace(ws);
wl_signal_emit_mutable(&manager->events.commit, manager); wl_signal_emit_mutable(&manager->events.commit, manager);
} }
static void workspace_manager_stop(struct wl_client *client, static void workspace_manager_stop(struct wl_client* client, struct wl_resource* resource) {
struct wl_resource *resource) {
struct wlr_ext_workspace_manager_v1* manager = manager_from_resource(resource); struct wlr_ext_workspace_manager_v1* manager = manager_from_resource(resource);
if (!manager) { if (!manager) {
return; return;
@ -593,24 +538,20 @@ static void workspace_manager_resource_destroy( struct wl_resource *resource) {
wl_list_remove(wl_resource_get_link(resource)); wl_list_remove(wl_resource_get_link(resource));
} }
static void workspace_manager_bind(struct wl_client *client, void *data, static void workspace_manager_bind(struct wl_client* client, void* data, uint32_t version, uint32_t id) {
uint32_t version, uint32_t id) {
struct wlr_ext_workspace_manager_v1* manager = (wlr_ext_workspace_manager_v1*)data; struct wlr_ext_workspace_manager_v1* manager = (wlr_ext_workspace_manager_v1*)data;
struct wl_resource *resource = wl_resource_create(client, struct wl_resource* resource = wl_resource_create(client, &zext_workspace_manager_v1_interface, version, id);
&zext_workspace_manager_v1_interface, version, id);
if (!resource) { if (!resource) {
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
return; return;
} }
wl_resource_set_implementation(resource, &workspace_manager_impl, wl_resource_set_implementation(resource, &workspace_manager_impl, manager, workspace_manager_resource_destroy);
manager, workspace_manager_resource_destroy);
wl_list_insert(&manager->resources, wl_resource_get_link(resource)); wl_list_insert(&manager->resources, wl_resource_get_link(resource));
struct wlr_ext_workspace_group_handle_v1 *group, *tmp; struct wlr_ext_workspace_group_handle_v1 *group, *tmp;
wl_list_for_each_safe(group, tmp, &manager->groups, link) { wl_list_for_each_safe(group, tmp, &manager->groups, link) {
struct wl_resource *group_resource = struct wl_resource* group_resource = create_workspace_group_resource_for_resource(group, resource);
create_workspace_group_resource_for_resource(group, resource);
group_send_details_to_resource(group, group_resource); group_send_details_to_resource(group, group_resource);
} }
@ -618,8 +559,7 @@ static void workspace_manager_bind(struct wl_client *client, void *data,
} }
static void handle_display_destroy(struct wl_listener* listener, void* data) { static void handle_display_destroy(struct wl_listener* listener, void* data) {
struct wlr_ext_workspace_manager_v1 *manager = struct wlr_ext_workspace_manager_v1* manager = wl_container_of(listener, manager, display_destroy);
wl_container_of(listener, manager, display_destroy);
wl_signal_emit_mutable(&manager->events.destroy, manager); wl_signal_emit_mutable(&manager->events.destroy, manager);
wl_list_remove(&manager->display_destroy.link); wl_list_remove(&manager->display_destroy.link);
@ -628,20 +568,15 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
free(manager); free(manager);
} }
struct wlr_ext_workspace_manager_v1 *wlr_ext_workspace_manager_v1_create( struct wlr_ext_workspace_manager_v1* wlr_ext_workspace_manager_v1_create(struct wl_display* display) {
struct wl_display *display) {
struct wlr_ext_workspace_manager_v1 *manager = (wlr_ext_workspace_manager_v1 *)calloc(1, struct wlr_ext_workspace_manager_v1* manager = (wlr_ext_workspace_manager_v1*)calloc(1, sizeof(struct wlr_ext_workspace_manager_v1));
sizeof(struct wlr_ext_workspace_manager_v1));
if (!manager) { if (!manager) {
return NULL; return NULL;
} }
manager->event_loop = wl_display_get_event_loop(display); manager->event_loop = wl_display_get_event_loop(display);
manager->global = wl_global_create(display, manager->global = wl_global_create(display, &zext_workspace_manager_v1_interface, WORKSPACE_V1_VERSION, manager, workspace_manager_bind);
&zext_workspace_manager_v1_interface,
WORKSPACE_V1_VERSION, manager,
workspace_manager_bind);
if (!manager->global) { if (!manager->global) {
free(manager); free(manager);
return NULL; return NULL;

View file

@ -74,6 +74,7 @@ struct wlr_ext_workspace_handle_v1 {
// request from the client // request from the client
uint32_t pending, current; uint32_t pending, current;
bool requestsActivate;
// set by the compositor // set by the compositor
uint32_t server_state; uint32_t server_state;
@ -89,48 +90,36 @@ struct wlr_ext_workspace_handle_v1 {
void* data; void* data;
}; };
struct wlr_ext_workspace_manager_v1 *wlr_ext_workspace_manager_v1_create( struct wlr_ext_workspace_manager_v1* wlr_ext_workspace_manager_v1_create(struct wl_display* display);
struct wl_display *display);
struct wlr_ext_workspace_group_handle_v1 *wlr_ext_workspace_group_handle_v1_create( struct wlr_ext_workspace_group_handle_v1* wlr_ext_workspace_group_handle_v1_create(struct wlr_ext_workspace_manager_v1* manager);
struct wlr_ext_workspace_manager_v1 *manager);
/** /**
* Destroy the workspace group and all workspaces inside it. * Destroy the workspace group and all workspaces inside it.
*/ */
void wlr_ext_workspace_group_handle_v1_destroy( void wlr_ext_workspace_group_handle_v1_destroy(struct wlr_ext_workspace_group_handle_v1* group);
struct wlr_ext_workspace_group_handle_v1 *group);
/** /**
* Create a new workspace in the workspace group. * Create a new workspace in the workspace group.
* Note that the compositor must set the workspace name immediately after * Note that the compositor must set the workspace name immediately after
* creating it. * creating it.
*/ */
struct wlr_ext_workspace_handle_v1 *wlr_ext_workspace_handle_v1_create( struct wlr_ext_workspace_handle_v1* wlr_ext_workspace_handle_v1_create(struct wlr_ext_workspace_group_handle_v1* group);
struct wlr_ext_workspace_group_handle_v1 *group);
void wlr_ext_workspace_handle_v1_destroy( void wlr_ext_workspace_handle_v1_destroy(struct wlr_ext_workspace_handle_v1* workspace);
struct wlr_ext_workspace_handle_v1 *workspace);
void wlr_ext_workspace_group_handle_v1_output_enter( void wlr_ext_workspace_group_handle_v1_output_enter(struct wlr_ext_workspace_group_handle_v1* group, struct wlr_output* output);
struct wlr_ext_workspace_group_handle_v1 *group, struct wlr_output *output);
void wlr_ext_workspace_group_handle_v1_output_leave( void wlr_ext_workspace_group_handle_v1_output_leave(struct wlr_ext_workspace_group_handle_v1* group, struct wlr_output* output);
struct wlr_ext_workspace_group_handle_v1 *group, struct wlr_output *output);
void wlr_ext_workspace_handle_v1_set_name( void wlr_ext_workspace_handle_v1_set_name(struct wlr_ext_workspace_handle_v1* workspace, const char* name);
struct wlr_ext_workspace_handle_v1 *workspace, const char* name);
void wlr_ext_workspace_handle_v1_set_coordinates( void wlr_ext_workspace_handle_v1_set_coordinates(struct wlr_ext_workspace_handle_v1* workspace, struct wl_array* coordinates);
struct wlr_ext_workspace_handle_v1 *workspace, struct wl_array *coordinates);
void wlr_ext_workspace_handle_v1_set_active( void wlr_ext_workspace_handle_v1_set_active(struct wlr_ext_workspace_handle_v1* workspace, bool active);
struct wlr_ext_workspace_handle_v1 *workspace, bool active);
void wlr_ext_workspace_handle_v1_set_urgent( void wlr_ext_workspace_handle_v1_set_urgent(struct wlr_ext_workspace_handle_v1* workspace, bool urgent);
struct wlr_ext_workspace_handle_v1 *workspace, bool urgent);
void wlr_ext_workspace_handle_v1_set_hidden( void wlr_ext_workspace_handle_v1_set_hidden(struct wlr_ext_workspace_handle_v1* workspace, bool hidden);
struct wlr_ext_workspace_handle_v1 *workspace, bool hidden);
#endif #endif