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;
}
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) {
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))

View file

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

View file

@ -8,32 +8,27 @@
#include "wlr_ext_workspace_v1.hpp"
#include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h>
#include "../Compositor.hpp"
#define WORKSPACE_V1_VERSION 1
static void workspace_handle_destroy(struct wl_client *client,
struct wl_resource *resource) ;
static void workspace_handle_destroy(struct wl_client* client, struct wl_resource* resource);
static void workspace_handle_activate(struct wl_client *client,
struct wl_resource *resource) ;
static void workspace_handle_activate(struct wl_client* client, struct wl_resource* resource);
static void workspace_handle_deactivate(struct wl_client *client,
struct wl_resource *resource) ;
static void workspace_handle_deactivate(struct wl_client* client, struct wl_resource* resource);
static void workspace_handle_remove(struct wl_client *client,
struct wl_resource *resource) ;
static void workspace_handle_remove(struct wl_client* client, struct wl_resource* resource);
static void workspace_group_handle_handle_create_workspace(struct wl_client *client,
struct wl_resource *resource, const char *arg) ;
static void workspace_group_handle_handle_create_workspace(struct wl_client* client, struct wl_resource* resource, const char* arg);
static void workspace_group_handle_handle_destroy(struct wl_client *client,
struct wl_resource *resource) ;
static void workspace_group_handle_handle_destroy(struct wl_client* client, struct wl_resource* resource);
static void workspace_manager_commit(struct wl_client *client,
struct wl_resource *resource) ;
static void workspace_manager_commit(struct wl_client* client, struct wl_resource* resource);
static void workspace_manager_stop(struct wl_client *client,
struct wl_resource *resource) ;
static void workspace_manager_stop(struct wl_client* client, struct wl_resource* resource);
//
inline static struct zext_workspace_handle_v1_interface workspace_handle_impl = {
.destroy = workspace_handle_destroy,
@ -52,9 +47,9 @@ inline static struct zext_workspace_manager_v1_interface workspace_manager_impl
.stop = workspace_manager_stop,
};
static void workspace_manager_idle_send_done(void *data) {
struct wlr_ext_workspace_manager_v1 *manager = (wlr_ext_workspace_manager_v1*)data;
struct wl_resource *resource, *tmp;
static void workspace_manager_idle_send_done(void* data) {
struct wlr_ext_workspace_manager_v1* manager = (wlr_ext_workspace_manager_v1*)data;
struct wl_resource * resource, *tmp;
wl_resource_for_each_safe(resource, tmp, &manager->resources) {
zext_workspace_manager_v1_send_done(resource);
}
@ -62,50 +57,40 @@ static void workspace_manager_idle_send_done(void *data) {
manager->idle_source = NULL;
}
static void workspace_manager_update_idle_source(
struct wlr_ext_workspace_manager_v1 *manager) {
static void workspace_manager_update_idle_source(struct wlr_ext_workspace_manager_v1* manager) {
if (manager->idle_source) {
return;
}
manager->idle_source = wl_event_loop_add_idle(manager->event_loop,
workspace_manager_idle_send_done, manager);
manager->idle_source = wl_event_loop_add_idle(manager->event_loop, workspace_manager_idle_send_done, manager);
}
static struct wlr_ext_workspace_handle_v1 *workspace_from_resource(
struct wl_resource *resource) {
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);
static struct wlr_ext_workspace_handle_v1* workspace_from_resource(struct wl_resource* resource) {
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);
}
static struct wlr_ext_workspace_group_handle_v1 *workspace_group_from_resource(
struct wl_resource *resource) {
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);
static struct wlr_ext_workspace_group_handle_v1* workspace_group_from_resource(struct wl_resource* resource) {
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);
}
static void workspace_handle_destroy(struct wl_client *client,
struct wl_resource *resource) {
static void workspace_handle_destroy(struct wl_client* client, struct wl_resource* resource) {
wl_resource_destroy(resource);
}
static void workspace_handle_activate(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_ext_workspace_handle_v1 *workspace = workspace_from_resource(resource);
static void workspace_handle_activate(struct wl_client* client, struct wl_resource* resource) {
struct wlr_ext_workspace_handle_v1* workspace = workspace_from_resource(resource);
if (!workspace) {
return;
}
workspace->pending |= WLR_EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE;
workspace->requestsActivate = true;
}
static void workspace_handle_remove(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_ext_workspace_handle_v1 *workspace = workspace_from_resource(resource);
static void workspace_handle_remove(struct wl_client* client, struct wl_resource* resource) {
struct wlr_ext_workspace_handle_v1* workspace = workspace_from_resource(resource);
if (!workspace) {
return;
}
@ -113,9 +98,8 @@ static void workspace_handle_remove(struct wl_client *client,
wl_signal_emit_mutable(&workspace->events.remove_request, NULL);
}
static void workspace_handle_deactivate(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_ext_workspace_handle_v1 *workspace = workspace_from_resource(resource);
static void workspace_handle_deactivate(struct wl_client* client, struct wl_resource* resource) {
struct wlr_ext_workspace_handle_v1* workspace = workspace_from_resource(resource);
if (!workspace) {
return;
}
@ -123,12 +107,12 @@ static void workspace_handle_deactivate(struct wl_client *client,
workspace->pending &= ~WLR_EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE;
}
static void workspace_handle_resource_destroy(struct wl_resource *resource) {
static void workspace_handle_resource_destroy(struct wl_resource* resource) {
wl_list_remove(wl_resource_get_link(resource));
}
static bool push_entry_in_array(struct wl_array *array, uint32_t entry) {
uint32_t *index = (uint32_t *)wl_array_add(array, sizeof(uint32_t));
static bool push_entry_in_array(struct wl_array* array, uint32_t entry) {
uint32_t* index = (uint32_t*)wl_array_add(array, sizeof(uint32_t));
if (index == NULL) {
return false;
}
@ -136,33 +120,27 @@ static bool push_entry_in_array(struct wl_array *array, uint32_t entry) {
return true;
}
static bool fill_array_from_workspace_state(struct wl_array *array,
uint32_t state) {
if ((state & WLR_EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE) &&
!push_entry_in_array(array, ZEXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE)) {
static bool fill_array_from_workspace_state(struct wl_array* array, uint32_t state) {
if ((state & WLR_EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE) && !push_entry_in_array(array, ZEXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE)) {
return false;
}
if ((state & WLR_EXT_WORKSPACE_HANDLE_V1_STATE_URGENT) &&
!push_entry_in_array(array, ZEXT_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)) {
return false;
}
if ((state & WLR_EXT_WORKSPACE_HANDLE_V1_STATE_HIDDEN) &&
!push_entry_in_array(array, ZEXT_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)) {
return false;
}
return true;
}
static void workspace_handle_send_details_to_resource(
struct wlr_ext_workspace_handle_v1 *workspace, struct wl_resource *resource) {
static void workspace_handle_send_details_to_resource(struct wlr_ext_workspace_handle_v1* workspace, struct wl_resource* resource) {
if (workspace->name) {
zext_workspace_handle_v1_send_name(resource, workspace->name);
}
if (workspace->coordinates.size > 0) {
zext_workspace_handle_v1_send_coordinates(resource,
&workspace->coordinates);
zext_workspace_handle_v1_send_coordinates(resource, &workspace->coordinates);
}
struct wl_array state;
@ -176,10 +154,7 @@ static void workspace_handle_send_details_to_resource(
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);
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);
}
void wlr_ext_workspace_handle_v1_set_coordinates(
struct wlr_ext_workspace_handle_v1 *workspace, struct wl_array *coordinates) {
void wlr_ext_workspace_handle_v1_set_coordinates(struct wlr_ext_workspace_handle_v1* workspace, struct wl_array* coordinates) {
wl_array_copy(&workspace->coordinates, coordinates);
struct wl_resource *tmp, *resource;
@ -203,12 +177,12 @@ void wlr_ext_workspace_handle_v1_set_coordinates(
workspace_manager_update_idle_source(workspace->group->manager);
}
static void workspace_send_state(struct wlr_ext_workspace_handle_v1 *workspace) {
static void workspace_send_state(struct wlr_ext_workspace_handle_v1* workspace) {
struct wl_array state;
wl_array_init(&state);
if (!fill_array_from_workspace_state(&state, workspace->server_state)) {
struct wl_resource *resource;
struct wl_resource* resource;
wl_resource_for_each(resource, &workspace->resources) {
wl_resource_post_no_memory(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);
}
void wlr_ext_workspace_handle_v1_set_active(
struct wlr_ext_workspace_handle_v1 *workspace, bool activate) {
void wlr_ext_workspace_handle_v1_set_active(struct wlr_ext_workspace_handle_v1* workspace, bool activate) {
if (activate) {
workspace->server_state |= WLR_EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE;
} else {
@ -237,8 +210,7 @@ void wlr_ext_workspace_handle_v1_set_active(
workspace_send_state(workspace);
}
void wlr_ext_workspace_handle_v1_set_urgent(
struct wlr_ext_workspace_handle_v1 *workspace, bool urgent) {
void wlr_ext_workspace_handle_v1_set_urgent(struct wlr_ext_workspace_handle_v1* workspace, bool urgent) {
if (urgent) {
workspace->server_state |= WLR_EXT_WORKSPACE_HANDLE_V1_STATE_URGENT;
} else {
@ -248,8 +220,7 @@ void wlr_ext_workspace_handle_v1_set_urgent(
workspace_send_state(workspace);
}
void wlr_ext_workspace_handle_v1_set_hidden(
struct wlr_ext_workspace_handle_v1 *workspace, bool hidden) {
void wlr_ext_workspace_handle_v1_set_hidden(struct wlr_ext_workspace_handle_v1* workspace, bool hidden) {
if (hidden) {
workspace->server_state |= WLR_EXT_WORKSPACE_HANDLE_V1_STATE_HIDDEN;
} else {
@ -259,21 +230,16 @@ void wlr_ext_workspace_handle_v1_set_hidden(
workspace_send_state(workspace);
}
static struct wl_resource *create_workspace_resource_for_group_resource(
struct wlr_ext_workspace_handle_v1 *workspace,
struct wl_resource *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 wl_client *client = wl_resource_get_client(group_resource);
struct wl_resource *resource = wl_resource_create(client,
&zext_workspace_handle_v1_interface,
wl_resource_get_version(group_resource), 0);
struct wl_client* client = wl_resource_get_client(group_resource);
struct wl_resource* resource = wl_resource_create(client, &zext_workspace_handle_v1_interface, wl_resource_get_version(group_resource), 0);
if (!resource) {
wl_client_post_no_memory(client);
return NULL;
}
wl_resource_set_implementation(resource, &workspace_handle_impl, workspace,
workspace_handle_resource_destroy);
wl_resource_set_implementation(resource, &workspace_handle_impl, workspace, workspace_handle_resource_destroy);
wl_list_insert(&workspace->resources, wl_resource_get_link(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;
}
struct wlr_ext_workspace_handle_v1 *wlr_ext_workspace_handle_v1_create(
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* wlr_ext_workspace_handle_v1_create(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));
if (!workspace) {
return NULL;
}
@ -304,8 +268,7 @@ struct wlr_ext_workspace_handle_v1 *wlr_ext_workspace_handle_v1_create(
return workspace;
}
void wlr_ext_workspace_handle_v1_destroy(
struct wlr_ext_workspace_handle_v1 *workspace) {
void wlr_ext_workspace_handle_v1_destroy(struct wlr_ext_workspace_handle_v1* workspace) {
if (!workspace) {
return;
}
@ -328,10 +291,8 @@ void wlr_ext_workspace_handle_v1_destroy(
free(workspace->name);
}
static void workspace_group_handle_handle_create_workspace(struct wl_client *client,
struct wl_resource *resource, const char *arg) {
struct wlr_ext_workspace_group_handle_v1 *group =
workspace_group_from_resource(resource);
static void workspace_group_handle_handle_create_workspace(struct wl_client* client, 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_create_workspace_event event;
event.workspace_group = group;
@ -339,108 +300,90 @@ static void workspace_group_handle_handle_create_workspace(struct wl_client *cli
wl_signal_emit_mutable(&group->events.create_workspace_request, &event);
}
static void workspace_group_handle_handle_destroy(struct wl_client *client,
struct wl_resource *resource) {
static void workspace_group_handle_handle_destroy(struct wl_client* client, struct wl_resource* resource) {
wl_resource_destroy(resource);
}
static void workspace_group_resource_destroy(struct wl_resource *resource) {
static void workspace_group_resource_destroy(struct wl_resource* resource) {
wl_list_remove(wl_resource_get_link(resource));
}
/**
* Create the workspace group resource and child workspace resources as well.
*/
static struct wl_resource *create_workspace_group_resource_for_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_resource *resource = wl_resource_create(client,
&zext_workspace_group_handle_v1_interface,
wl_resource_get_version(manager_resource), 0);
static struct wl_resource* create_workspace_group_resource_for_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_resource* resource = wl_resource_create(client, &zext_workspace_group_handle_v1_interface, wl_resource_get_version(manager_resource), 0);
if (!resource) {
wl_client_post_no_memory(client);
return NULL;
}
wl_resource_set_implementation(resource, &workspace_group_impl, group,
workspace_group_resource_destroy);
wl_resource_set_implementation(resource, &workspace_group_impl, group, workspace_group_resource_destroy);
wl_list_insert(&group->resources, wl_resource_get_link(resource));
zext_workspace_manager_v1_send_workspace_group(manager_resource, resource);
struct wlr_ext_workspace_handle_v1 *tmp, *workspace;
wl_list_for_each_safe(workspace, tmp, &group->workspaces, link) {
struct wl_resource *workspace_resource =
create_workspace_resource_for_group_resource(workspace, resource);
struct wl_resource* workspace_resource = create_workspace_resource_for_group_resource(workspace, resource);
workspace_handle_send_details_to_resource(workspace, workspace_resource);
}
return resource;
}
static void send_output_to_group_resource(struct wl_resource *group_resource,
struct wlr_output *output, bool enter) {
struct wl_client *client = wl_resource_get_client(group_resource);
static void send_output_to_group_resource(struct wl_resource* group_resource, struct wlr_output* output, bool enter) {
struct wl_client* client = wl_resource_get_client(group_resource);
struct wl_resource *output_resource, *tmp;
wl_resource_for_each_safe(output_resource, tmp, &output->resources) {
if (wl_resource_get_client(output_resource) == client) {
if (enter) {
zext_workspace_group_handle_v1_send_output_enter(group_resource,
output_resource);
zext_workspace_group_handle_v1_send_output_enter(group_resource, output_resource);
} else {
zext_workspace_group_handle_v1_send_output_leave(group_resource,
output_resource);
zext_workspace_group_handle_v1_send_output_leave(group_resource, output_resource);
}
}
}
}
static void group_send_output(struct wlr_ext_workspace_group_handle_v1 *group,
struct wlr_output *output, bool enter) {
static void group_send_output(struct wlr_ext_workspace_group_handle_v1* group, struct wlr_output* output, bool enter) {
struct wl_resource *resource, *tmp;
wl_resource_for_each_safe(resource, tmp, &group->resources) {
send_output_to_group_resource(resource, output, enter);
}
}
static void workspace_handle_output_bind(struct wl_listener *listener,
void *data) {
struct wlr_output_event_bind *evt = (wlr_output_event_bind *)data;
struct wlr_ext_workspace_group_handle_v1_output *output =
wl_container_of(listener, output, output_bind);
struct wl_client *client = wl_resource_get_client(evt->resource);
static void workspace_handle_output_bind(struct wl_listener* listener, void* data) {
struct wlr_output_event_bind* evt = (wlr_output_event_bind*)data;
struct wlr_ext_workspace_group_handle_v1_output* output = wl_container_of(listener, output, output_bind);
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) {
if (client == wl_resource_get_client(group_resource)) {
zext_workspace_group_handle_v1_send_output_enter(group_resource,
evt->resource);
zext_workspace_group_handle_v1_send_output_enter(group_resource, evt->resource);
}
}
workspace_manager_update_idle_source(output->group_handle->manager);
}
static void workspace_handle_output_destroy(struct wl_listener *listener,
void *data) {
struct wlr_ext_workspace_group_handle_v1_output *output =
wl_container_of(listener, output, output_destroy);
wlr_ext_workspace_group_handle_v1_output_leave(output->group_handle,
output->output);
static void workspace_handle_output_destroy(struct wl_listener* listener, void* data) {
struct wlr_ext_workspace_group_handle_v1_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(
struct wlr_ext_workspace_group_handle_v1 *group, struct wlr_output *output) {
struct wlr_ext_workspace_group_handle_v1_output *group_output;
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_output* group_output;
wl_list_for_each(group_output, &group->outputs, link) {
if (group_output->output == output) {
return; // we have already sent output_enter event
}
}
group_output = (wlr_ext_workspace_group_handle_v1_output *)calloc(1, sizeof(struct wlr_ext_workspace_group_handle_v1_output));
group_output = (wlr_ext_workspace_group_handle_v1_output*)calloc(1, sizeof(struct wlr_ext_workspace_group_handle_v1_output));
if (!group_output) {
wlr_log(WLR_ERROR, "failed to allocate memory for workspace output");
return;
@ -459,17 +402,15 @@ void wlr_ext_workspace_group_handle_v1_output_enter(
group_send_output(group, output, true);
}
static void group_output_destroy(
struct wlr_ext_workspace_group_handle_v1_output *output) {
static void group_output_destroy(struct wlr_ext_workspace_group_handle_v1_output* output) {
wl_list_remove(&output->link);
wl_list_remove(&output->output_destroy.link);
free(output);
}
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_output *group_output_iterator;
struct wlr_ext_workspace_group_handle_v1_output *group_output = NULL;
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_output* group_output_iterator;
struct wlr_ext_workspace_group_handle_v1_output* group_output = NULL;
wl_list_for_each(group_output_iterator, &group->outputs, link) {
if (group_output_iterator->output == output) {
@ -486,20 +427,16 @@ void wlr_ext_workspace_group_handle_v1_output_leave(
}
}
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_output *output;
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_output* output;
wl_list_for_each(output, &group->outputs, link) {
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_manager_v1 *manager) {
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_group_handle_v1 *group = (wlr_ext_workspace_group_handle_v1 *)calloc(1,
sizeof(struct wlr_ext_workspace_group_handle_v1));
struct wlr_ext_workspace_group_handle_v1* group = (wlr_ext_workspace_group_handle_v1*)calloc(1, sizeof(struct wlr_ext_workspace_group_handle_v1));
if (!group) {
return NULL;
}
@ -521,8 +458,7 @@ struct wlr_ext_workspace_group_handle_v1 *wlr_ext_workspace_group_handle_v1_crea
return group;
}
void wlr_ext_workspace_group_handle_v1_destroy(
struct wlr_ext_workspace_group_handle_v1 *group) {
void wlr_ext_workspace_group_handle_v1_destroy(struct wlr_ext_workspace_group_handle_v1* group) {
if (!group) {
return;
}
@ -552,35 +488,44 @@ void wlr_ext_workspace_group_handle_v1_destroy(
free(group);
}
static struct wlr_ext_workspace_manager_v1 *manager_from_resource(
struct wl_resource *resource) {
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);
static struct wlr_ext_workspace_manager_v1* manager_from_resource(struct wl_resource* resource) {
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);
}
static void workspace_manager_commit(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_ext_workspace_manager_v1 *manager = manager_from_resource(resource);
static void workspace_manager_commit(struct wl_client* client, struct wl_resource* resource) {
struct wlr_ext_workspace_manager_v1* manager = manager_from_resource(resource);
if (!manager) {
return;
}
struct wlr_ext_workspace_group_handle_v1 *group;
struct wlr_ext_workspace_handle_v1 *workspace;
std::vector<CWorkspace*> toSwitchTo;
struct wlr_ext_workspace_group_handle_v1* group;
struct wlr_ext_workspace_handle_v1* workspace;
wl_list_for_each(group, &manager->groups, 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;
}
}
for (auto& ws : toSwitchTo)
g_pCompositor->getMonitorFromID(ws->m_iMonitorID)->changeWorkspace(ws);
wl_signal_emit_mutable(&manager->events.commit, manager);
}
static void workspace_manager_stop(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_ext_workspace_manager_v1 *manager = manager_from_resource(resource);
static void workspace_manager_stop(struct wl_client* client, struct wl_resource* resource) {
struct wlr_ext_workspace_manager_v1* manager = manager_from_resource(resource);
if (!manager) {
return;
}
@ -589,37 +534,32 @@ static void workspace_manager_stop(struct wl_client *client,
wl_resource_destroy(resource);
}
static void workspace_manager_resource_destroy( struct wl_resource *resource) {
static void workspace_manager_resource_destroy(struct wl_resource* resource) {
wl_list_remove(wl_resource_get_link(resource));
}
static void workspace_manager_bind(struct wl_client *client, void *data,
uint32_t version, uint32_t id) {
struct wlr_ext_workspace_manager_v1 *manager = (wlr_ext_workspace_manager_v1 *)data;
struct wl_resource *resource = wl_resource_create(client,
&zext_workspace_manager_v1_interface, version, id);
static void workspace_manager_bind(struct wl_client* client, void* data, uint32_t version, uint32_t id) {
struct wlr_ext_workspace_manager_v1* manager = (wlr_ext_workspace_manager_v1*)data;
struct wl_resource* resource = wl_resource_create(client, &zext_workspace_manager_v1_interface, version, id);
if (!resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(resource, &workspace_manager_impl,
manager, workspace_manager_resource_destroy);
wl_resource_set_implementation(resource, &workspace_manager_impl, manager, workspace_manager_resource_destroy);
wl_list_insert(&manager->resources, wl_resource_get_link(resource));
struct wlr_ext_workspace_group_handle_v1 *group, *tmp;
wl_list_for_each_safe(group, tmp, &manager->groups, link) {
struct wl_resource *group_resource =
create_workspace_group_resource_for_resource(group, resource);
struct wl_resource* group_resource = create_workspace_group_resource_for_resource(group, resource);
group_send_details_to_resource(group, group_resource);
}
zext_workspace_manager_v1_send_done(resource);
}
static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_ext_workspace_manager_v1 *manager =
wl_container_of(listener, manager, display_destroy);
static void handle_display_destroy(struct wl_listener* listener, void* data) {
struct wlr_ext_workspace_manager_v1* manager = wl_container_of(listener, manager, display_destroy);
wl_signal_emit_mutable(&manager->events.destroy, manager);
wl_list_remove(&manager->display_destroy.link);
@ -628,20 +568,15 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
free(manager);
}
struct wlr_ext_workspace_manager_v1 *wlr_ext_workspace_manager_v1_create(
struct wl_display *display) {
struct wlr_ext_workspace_manager_v1* wlr_ext_workspace_manager_v1_create(struct wl_display* display) {
struct wlr_ext_workspace_manager_v1 *manager = (wlr_ext_workspace_manager_v1 *)calloc(1,
sizeof(struct wlr_ext_workspace_manager_v1));
struct wlr_ext_workspace_manager_v1* manager = (wlr_ext_workspace_manager_v1*)calloc(1, sizeof(struct wlr_ext_workspace_manager_v1));
if (!manager) {
return NULL;
}
manager->event_loop = wl_display_get_event_loop(display);
manager->global = wl_global_create(display,
&zext_workspace_manager_v1_interface,
WORKSPACE_V1_VERSION, manager,
workspace_manager_bind);
manager->global = wl_global_create(display, &zext_workspace_manager_v1_interface, WORKSPACE_V1_VERSION, manager, workspace_manager_bind);
if (!manager->global) {
free(manager);
return NULL;

View file

@ -10,10 +10,10 @@
#include <wlr/types/wlr_output.h>
struct wlr_ext_workspace_manager_v1 {
struct wl_event_loop *event_loop;
struct wl_event_source *idle_source;
struct wl_event_loop* event_loop;
struct wl_event_source* idle_source;
struct wl_global *global;
struct wl_global* global;
struct wl_list resources; // wl_resource_get_link
struct wl_list groups; // wlr_ext_workspace_group_handle_v1::link
@ -24,7 +24,7 @@ struct wlr_ext_workspace_manager_v1 {
struct wl_signal destroy;
} events;
void *data;
void* data;
};
struct wlr_ext_workspace_group_handle_v1 {
@ -34,7 +34,7 @@ struct wlr_ext_workspace_group_handle_v1 {
struct wl_list workspaces; // wlr_ext_workspace_handle_v1::link
struct wl_list outputs; // wlr_ext_workspace_group_handle_v1_output::link
struct wlr_ext_workspace_manager_v1 *manager;
struct wlr_ext_workspace_manager_v1* manager;
struct {
// wlr_ext_workspace_group_handle_v1_create_workspace_event
@ -42,21 +42,21 @@ struct wlr_ext_workspace_group_handle_v1 {
struct wl_signal destroy;
} events;
void *data;
void* data;
};
struct wlr_ext_workspace_group_handle_v1_create_workspace_event {
struct wlr_ext_workspace_group_handle_v1 *workspace_group;
const char *name;
struct wlr_ext_workspace_group_handle_v1* workspace_group;
const char* name;
};
struct wlr_ext_workspace_group_handle_v1_output {
struct wl_list link; // wlr_ext_workspace_group_handle_v1::outputs
struct wl_listener output_bind;
struct wl_listener output_destroy;
struct wlr_output *output;
struct wlr_output* output;
struct wlr_ext_workspace_group_handle_v1 *group_handle;
struct wlr_ext_workspace_group_handle_v1* group_handle;
};
enum wlr_ext_workspace_handle_v1_state
@ -70,15 +70,16 @@ struct wlr_ext_workspace_handle_v1 {
struct wl_list link; // wlr_ext_workspace_group_handle_v1::workspaces
struct wl_list resources;
struct wlr_ext_workspace_group_handle_v1 *group;
struct wlr_ext_workspace_group_handle_v1* group;
// request from the client
uint32_t pending, current;
bool requestsActivate;
// set by the compositor
uint32_t server_state;
char *name;
char* name;
struct wl_array coordinates;
struct {
@ -86,51 +87,39 @@ struct wlr_ext_workspace_handle_v1 {
struct wl_signal destroy;
} events;
void *data;
void* data;
};
struct wlr_ext_workspace_manager_v1 *wlr_ext_workspace_manager_v1_create(
struct wl_display *display);
struct wlr_ext_workspace_manager_v1* wlr_ext_workspace_manager_v1_create(struct wl_display* display);
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_group_handle_v1* wlr_ext_workspace_group_handle_v1_create(struct wlr_ext_workspace_manager_v1* manager);
/**
* Destroy the workspace group and all workspaces inside it.
*/
void wlr_ext_workspace_group_handle_v1_destroy(
struct wlr_ext_workspace_group_handle_v1 *group);
void wlr_ext_workspace_group_handle_v1_destroy(struct wlr_ext_workspace_group_handle_v1* group);
/**
* Create a new workspace in the workspace group.
* Note that the compositor must set the workspace name immediately after
* creating it.
*/
struct wlr_ext_workspace_handle_v1 *wlr_ext_workspace_handle_v1_create(
struct wlr_ext_workspace_group_handle_v1 *group);
struct wlr_ext_workspace_handle_v1* wlr_ext_workspace_handle_v1_create(struct wlr_ext_workspace_group_handle_v1* group);
void wlr_ext_workspace_handle_v1_destroy(
struct wlr_ext_workspace_handle_v1 *workspace);
void wlr_ext_workspace_handle_v1_destroy(struct wlr_ext_workspace_handle_v1* workspace);
void wlr_ext_workspace_group_handle_v1_output_enter(
struct wlr_ext_workspace_group_handle_v1 *group, struct wlr_output *output);
void wlr_ext_workspace_group_handle_v1_output_enter(struct wlr_ext_workspace_group_handle_v1* group, struct wlr_output* output);
void wlr_ext_workspace_group_handle_v1_output_leave(
struct wlr_ext_workspace_group_handle_v1 *group, struct wlr_output *output);
void wlr_ext_workspace_group_handle_v1_output_leave(struct wlr_ext_workspace_group_handle_v1* group, struct wlr_output* output);
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);
void wlr_ext_workspace_handle_v1_set_coordinates(
struct wlr_ext_workspace_handle_v1 *workspace, struct wl_array *coordinates);
void wlr_ext_workspace_handle_v1_set_coordinates(struct wlr_ext_workspace_handle_v1* workspace, struct wl_array* coordinates);
void wlr_ext_workspace_handle_v1_set_active(
struct wlr_ext_workspace_handle_v1 *workspace, bool active);
void wlr_ext_workspace_handle_v1_set_active(struct wlr_ext_workspace_handle_v1* workspace, bool active);
void wlr_ext_workspace_handle_v1_set_urgent(
struct wlr_ext_workspace_handle_v1 *workspace, bool urgent);
void wlr_ext_workspace_handle_v1_set_urgent(struct wlr_ext_workspace_handle_v1* workspace, bool urgent);
void wlr_ext_workspace_handle_v1_set_hidden(
struct wlr_ext_workspace_handle_v1 *workspace, bool hidden);
void wlr_ext_workspace_handle_v1_set_hidden(struct wlr_ext_workspace_handle_v1* workspace, bool hidden);
#endif