fix: for ipc v2

This commit is contained in:
DreamMaoMao 2025-03-08 11:40:15 +08:00
parent 30d753b57f
commit 4d6da14c13
2 changed files with 149 additions and 128 deletions

258
maomao.c
View file

@ -256,7 +256,7 @@ struct Client {
typedef struct {
struct wl_list link;
struct wl_resource *resource;
Monitor *monitor;
Monitor *mon;
} DwlIpcOutput;
typedef struct {
@ -562,6 +562,7 @@ void scene_buffer_apply_opacity(struct wlr_scene_buffer *buffer, int sx, int sy,
Client *direction_select(const Arg *arg);
void bind_to_view(const Arg *arg);
void view_in_mon(const Arg *arg, bool want_animation, Monitor *m);
void toggletag(const Arg *arg);
void toggleview(const Arg *arg);
void tag(const Arg *arg);
@ -2836,67 +2837,69 @@ Monitor *dirtomon(enum wlr_direction dir) {
return selmon;
}
void dwl_ipc_manager_bind(struct wl_client *client, void *data,
uint32_t version, uint32_t id) {
struct wl_resource *manager_resource =
wl_resource_create(client, &zdwl_ipc_manager_v2_interface, version, id);
if (!manager_resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(manager_resource, &dwl_manager_implementation,
NULL, dwl_ipc_manager_destroy);
void
dwl_ipc_manager_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
struct wl_resource *manager_resource = wl_resource_create(client, &zdwl_ipc_manager_v2_interface, version, id);
if (!manager_resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(manager_resource, &dwl_manager_implementation, NULL, dwl_ipc_manager_destroy);
zdwl_ipc_manager_v2_send_tags(manager_resource, LENGTH(tags));
zdwl_ipc_manager_v2_send_tags(manager_resource, LENGTH(tags));
for (int i = 0; i < LENGTH(layouts); i++)
zdwl_ipc_manager_v2_send_layout(manager_resource, layouts[i].symbol);
for (unsigned int i = 0; i < LENGTH(layouts); i++)
zdwl_ipc_manager_v2_send_layout(manager_resource, layouts[i].symbol);
}
void dwl_ipc_manager_destroy(struct wl_resource *resource) {
/* No state to destroy */
void
dwl_ipc_manager_destroy(struct wl_resource *resource)
{
/* No state to destroy */
}
void dwl_ipc_manager_get_output(struct wl_client *client,
struct wl_resource *resource, uint32_t id,
struct wl_resource *output) {
DwlIpcOutput *ipc_output;
Monitor *monitor = wlr_output_from_resource(output)->data;
struct wl_resource *output_resource =
wl_resource_create(client, &zdwl_ipc_output_v2_interface,
wl_resource_get_version(resource), id);
if (!output_resource)
return;
void
dwl_ipc_manager_get_output(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *output)
{
DwlIpcOutput *ipc_output;
Monitor *monitor = wlr_output_from_resource(output)->data;
struct wl_resource *output_resource = wl_resource_create(client, &zdwl_ipc_output_v2_interface, wl_resource_get_version(resource), id);
if (!output_resource)
return;
ipc_output = ecalloc(1, sizeof(*ipc_output));
ipc_output->resource = output_resource;
ipc_output->monitor = monitor;
wl_resource_set_implementation(output_resource, &dwl_output_implementation,
ipc_output, dwl_ipc_output_destroy);
wl_list_insert(&monitor->dwl_ipc_outputs, &ipc_output->link);
dwl_ipc_output_printstatus_to(ipc_output);
ipc_output = ecalloc(1, sizeof(*ipc_output));
ipc_output->resource = output_resource;
ipc_output->mon = monitor;
wl_resource_set_implementation(output_resource, &dwl_output_implementation, ipc_output, dwl_ipc_output_destroy);
wl_list_insert(&monitor->dwl_ipc_outputs, &ipc_output->link);
dwl_ipc_output_printstatus_to(ipc_output);
}
void dwl_ipc_manager_release(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
void
dwl_ipc_manager_release(struct wl_client *client, struct wl_resource *resource)
{
wl_resource_destroy(resource);
}
// 在外部ipc客户端结束的时候会发出销毁请求,比如kill掉waybar,就会销毁waybar绑定的ipc_output
static void dwl_ipc_output_destroy(struct wl_resource *resource) {
DwlIpcOutput *ipc_output = wl_resource_get_user_data(resource);
wl_list_remove(&ipc_output->link);
free(ipc_output);
static void
dwl_ipc_output_destroy(struct wl_resource *resource)
{
DwlIpcOutput *ipc_output = wl_resource_get_user_data(resource);
wl_list_remove(&ipc_output->link);
free(ipc_output);
}
void dwl_ipc_output_printstatus(Monitor *monitor) {
DwlIpcOutput *ipc_output;
wl_list_for_each(ipc_output, &monitor->dwl_ipc_outputs, link)
dwl_ipc_output_printstatus_to(ipc_output);
void
dwl_ipc_output_printstatus(Monitor *monitor)
{
DwlIpcOutput *ipc_output;
wl_list_for_each(ipc_output, &monitor->dwl_ipc_outputs, link)
dwl_ipc_output_printstatus_to(ipc_output);
}
void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
Monitor *monitor = ipc_output->monitor;
Monitor *monitor = ipc_output->mon;
Client *c, *focused;
int tagmask, state, numclients, focused_client, tag;
const char *title, *appid, *symbol;
@ -2928,30 +2931,29 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
// numclients++;
// }
// zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state,
// numclients,
// zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, numclients,
// focused_client);
// }
// }
for (tag = 0; tag < LENGTH(tags); tag++) {
numclients = state = focused_client = 0;
tagmask = 1 << tag;
if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE;
wl_list_for_each(c, &clients, link) {
if (c->mon != monitor)
continue;
if (!(c->tags & tagmask))
continue;
if (c == focused)
focused_client = 1;
if (c->isurgent)
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT;
numclients++;
}
zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, numclients,
focused_client);
for ( tag = 0 ; tag < LENGTH(tags); tag++) {
numclients = state = focused_client = 0;
tagmask = 1 << tag;
if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE;
wl_list_for_each(c, &clients, link) {
if (c->mon != monitor)
continue;
if (!(c->tags & tagmask))
continue;
if (c == focused)
focused_client = 1;
if (c->isurgent)
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT;
numclients++;
}
zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state,
numclients, focused_client);
}
title = focused ? client_get_title(focused) : "";
@ -2959,39 +2961,46 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
symbol = monitor->pertag->ltidxs[monitor->pertag->curtag]->symbol;
zdwl_ipc_output_v2_send_layout(
ipc_output->resource,
monitor->pertag->ltidxs[monitor->pertag->curtag] - layouts);
ipc_output->resource,
monitor->pertag->ltidxs[monitor->pertag->curtag] - layouts);
zdwl_ipc_output_v2_send_title(ipc_output->resource, title ? title : broken);
zdwl_ipc_output_v2_send_appid(ipc_output->resource, appid ? appid : broken);
zdwl_ipc_output_v2_send_layout_symbol(ipc_output->resource, symbol);
zdwl_ipc_output_v2_send_frame(ipc_output->resource);
if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_FULLSCREEN_SINCE_VERSION) {
zdwl_ipc_output_v2_send_fullscreen(ipc_output->resource, focused ? focused->isfullscreen : 0);
}
if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) {
zdwl_ipc_output_v2_send_floating(ipc_output->resource, focused ? focused->isfloating : 0);
}
zdwl_ipc_output_v2_send_frame(ipc_output->resource);
}
void dwl_ipc_output_set_client_tags(struct wl_client *client,
struct wl_resource *resource,
uint32_t and_tags, uint32_t xor_tags) {
DwlIpcOutput *ipc_output;
Monitor *monitor;
Client *selected_client;
unsigned int newtags = 0;
void
dwl_ipc_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, uint32_t and_tags, uint32_t xor_tags)
{
DwlIpcOutput *ipc_output;
Monitor *monitor;
Client *selected_client;
unsigned int newtags = 0;
ipc_output = wl_resource_get_user_data(resource);
if (!ipc_output)
return;
ipc_output = wl_resource_get_user_data(resource);
if (!ipc_output)
return;
monitor = ipc_output->monitor;
selected_client = focustop(monitor);
if (!selected_client)
return;
monitor = ipc_output->mon;
selected_client = focustop(monitor);
if (!selected_client)
return;
newtags = (selected_client->tags & and_tags) ^ xor_tags;
if (!newtags)
return;
newtags = (selected_client->tags & and_tags) ^ xor_tags;
if (!newtags)
return;
selected_client->tags = newtags;
focusclient(focustop(selmon), 1);
arrange(selmon, true);
printstatus();
selected_client->tags = newtags;
if (selmon == monitor)
focusclient(focustop(monitor), 1);
arrange(selmon,false);
printstatus();
}
void dwl_ipc_output_set_layout(struct wl_client *client,
@ -3003,7 +3012,7 @@ void dwl_ipc_output_set_layout(struct wl_client *client,
if (!ipc_output)
return;
monitor = ipc_output->monitor;
monitor = ipc_output->mon;
if (index >= LENGTH(layouts))
index = 0;
@ -3012,32 +3021,25 @@ void dwl_ipc_output_set_layout(struct wl_client *client,
printstatus();
}
void dwl_ipc_output_set_tags(struct wl_client *client,
struct wl_resource *resource, uint32_t tagmask,
uint32_t toggle_tagset) {
DwlIpcOutput *ipc_output;
Monitor *monitor;
unsigned int newtags = tagmask & TAGMASK;
void
dwl_ipc_output_set_tags(struct wl_client *client, struct wl_resource *resource, uint32_t tagmask, uint32_t toggle_tagset)
{
DwlIpcOutput *ipc_output;
Monitor *monitor;
unsigned int newtags = tagmask & TAGMASK;
ipc_output = wl_resource_get_user_data(resource);
if (!ipc_output)
return;
monitor = ipc_output->monitor;
ipc_output = wl_resource_get_user_data(resource);
if (!ipc_output)
return;
monitor = ipc_output->mon;
if (!newtags || newtags == monitor->tagset[monitor->seltags])
return;
if (toggle_tagset)
monitor->seltags ^= 1;
monitor->tagset[monitor->seltags] = newtags;
focusclient(focustop(monitor), 1);
arrange(monitor, true);
printstatus();
view_in_mon(&(Arg){.ui = newtags}, true,monitor);
}
void dwl_ipc_output_release(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
void
dwl_ipc_output_release(struct wl_client *client, struct wl_resource *resource)
{
wl_resource_destroy(resource);
}
void focusclient(Client *c, int lift) {
@ -6189,39 +6191,43 @@ urgent(struct wl_listener *listener, void *data) {
void bind_to_view(const Arg *arg) { view(arg, true); }
void view(const Arg *arg, bool want_animation) {
void view_in_mon(const Arg *arg, bool want_animation, Monitor *m) {
size_t i, tmptag;
if (!selmon || (arg->ui != ~0 && selmon->isoverview)) {
if (!m || (arg->ui != ~0 && m->isoverview)) {
return;
}
if ((selmon->tagset[selmon->seltags] & arg->ui & TAGMASK) != 0) {
if ((m->tagset[m->seltags] & arg->ui & TAGMASK) != 0) {
want_animation = false;
}
selmon->seltags ^= 1; /* toggle sel tagset */
m->seltags ^= 1; /* toggle sel tagset */
if (arg->ui & TAGMASK) {
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
selmon->pertag->prevtag = selmon->pertag->curtag;
m->tagset[m->seltags] = arg->ui & TAGMASK;
m->pertag->prevtag = m->pertag->curtag;
if (arg->ui == ~0)
selmon->pertag->curtag = 0;
m->pertag->curtag = 0;
else {
for (i = 0; !(arg->ui & 1 << i); i++)
;
selmon->pertag->curtag = i + 1;
m->pertag->curtag = i + 1;
}
} else {
tmptag = selmon->pertag->prevtag;
selmon->pertag->prevtag = selmon->pertag->curtag;
selmon->pertag->curtag = tmptag;
tmptag = m->pertag->prevtag;
m->pertag->prevtag = m->pertag->curtag;
m->pertag->curtag = tmptag;
}
focusclient(focustop(selmon), 1);
arrange(selmon, want_animation);
focusclient(focustop(m), 1);
arrange(m, want_animation);
printstatus();
}
void view(const Arg *arg, bool want_animation) {
view_in_mon(arg, want_animation, selmon);
}
void viewtoleft(const Arg *arg) {
size_t tmptag;
unsigned int target = selmon->tagset[selmon->seltags];

View file

@ -19,7 +19,7 @@ I would probably just submit raphi's patchset but I don't think that would be po
reset.
</description>
<interface name="zdwl_ipc_manager_v2" version="1">
<interface name="zdwl_ipc_manager_v2" version="2">
<description summary="manage dwl state">
This interface is exposed as a global in wl_registry.
@ -60,7 +60,7 @@ I would probably just submit raphi's patchset but I don't think that would be po
</event>
</interface>
<interface name="zdwl_ipc_output_v2" version="1">
<interface name="zdwl_ipc_output_v2" version="2">
<description summary="control dwl output">
Observe and control a dwl output.
@ -162,5 +162,20 @@ I would probably just submit raphi's patchset but I don't think that would be po
<description summary="Set the layout of this output"/>
<arg name="index" type="uint" summary="index of a layout recieved by dwl_ipc_manager.layout"/>
</request>
<!-- Version 2 -->
<event name="fullscreen" since="2">
<description summary="Update fullscreen status">
Indicates if the selected client on this output is fullscreen.
</description>
<arg name="is_fullscreen" type="uint" summary="If the selected client is fullscreen. Nonzero is valid, zero invalid"/>
</event>
<event name="floating" since="2">
<description summary="Update the floating status">
Indicates if the selected client on this output is floating.
</description>
<arg name="is_floating" type="uint" summary="If the selected client is floating. Nonzero is valid, zero invalid"/>
</event>
</interface>
</protocol>