mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-05-03 06:46:38 -04:00
fix: for ipc v2
This commit is contained in:
parent
30d753b57f
commit
4d6da14c13
2 changed files with 149 additions and 128 deletions
258
maomao.c
258
maomao.c
|
|
@ -256,7 +256,7 @@ struct Client {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
struct wl_list link;
|
struct wl_list link;
|
||||||
struct wl_resource *resource;
|
struct wl_resource *resource;
|
||||||
Monitor *monitor;
|
Monitor *mon;
|
||||||
} DwlIpcOutput;
|
} DwlIpcOutput;
|
||||||
|
|
||||||
typedef struct {
|
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);
|
Client *direction_select(const Arg *arg);
|
||||||
void bind_to_view(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 toggletag(const Arg *arg);
|
||||||
void toggleview(const Arg *arg);
|
void toggleview(const Arg *arg);
|
||||||
void tag(const Arg *arg);
|
void tag(const Arg *arg);
|
||||||
|
|
@ -2836,67 +2837,69 @@ Monitor *dirtomon(enum wlr_direction dir) {
|
||||||
return selmon;
|
return selmon;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dwl_ipc_manager_bind(struct wl_client *client, void *data,
|
void
|
||||||
uint32_t version, uint32_t id) {
|
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);
|
struct wl_resource *manager_resource = wl_resource_create(client, &zdwl_ipc_manager_v2_interface, version, id);
|
||||||
if (!manager_resource) {
|
if (!manager_resource) {
|
||||||
wl_client_post_no_memory(client);
|
wl_client_post_no_memory(client);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
wl_resource_set_implementation(manager_resource, &dwl_manager_implementation,
|
wl_resource_set_implementation(manager_resource, &dwl_manager_implementation, NULL, dwl_ipc_manager_destroy);
|
||||||
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++)
|
for (unsigned int i = 0; i < LENGTH(layouts); i++)
|
||||||
zdwl_ipc_manager_v2_send_layout(manager_resource, layouts[i].symbol);
|
zdwl_ipc_manager_v2_send_layout(manager_resource, layouts[i].symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dwl_ipc_manager_destroy(struct wl_resource *resource) {
|
void
|
||||||
/* No state to destroy */
|
dwl_ipc_manager_destroy(struct wl_resource *resource)
|
||||||
|
{
|
||||||
|
/* No state to destroy */
|
||||||
}
|
}
|
||||||
|
|
||||||
void dwl_ipc_manager_get_output(struct wl_client *client,
|
void
|
||||||
struct wl_resource *resource, uint32_t id,
|
dwl_ipc_manager_get_output(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *output)
|
||||||
struct wl_resource *output) {
|
{
|
||||||
DwlIpcOutput *ipc_output;
|
DwlIpcOutput *ipc_output;
|
||||||
Monitor *monitor = wlr_output_from_resource(output)->data;
|
Monitor *monitor = wlr_output_from_resource(output)->data;
|
||||||
struct wl_resource *output_resource =
|
struct wl_resource *output_resource = wl_resource_create(client, &zdwl_ipc_output_v2_interface, wl_resource_get_version(resource), id);
|
||||||
wl_resource_create(client, &zdwl_ipc_output_v2_interface,
|
if (!output_resource)
|
||||||
wl_resource_get_version(resource), id);
|
return;
|
||||||
if (!output_resource)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ipc_output = ecalloc(1, sizeof(*ipc_output));
|
ipc_output = ecalloc(1, sizeof(*ipc_output));
|
||||||
ipc_output->resource = output_resource;
|
ipc_output->resource = output_resource;
|
||||||
ipc_output->monitor = monitor;
|
ipc_output->mon = monitor;
|
||||||
wl_resource_set_implementation(output_resource, &dwl_output_implementation,
|
wl_resource_set_implementation(output_resource, &dwl_output_implementation, ipc_output, dwl_ipc_output_destroy);
|
||||||
ipc_output, dwl_ipc_output_destroy);
|
wl_list_insert(&monitor->dwl_ipc_outputs, &ipc_output->link);
|
||||||
wl_list_insert(&monitor->dwl_ipc_outputs, &ipc_output->link);
|
dwl_ipc_output_printstatus_to(ipc_output);
|
||||||
dwl_ipc_output_printstatus_to(ipc_output);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dwl_ipc_manager_release(struct wl_client *client,
|
void
|
||||||
struct wl_resource *resource) {
|
dwl_ipc_manager_release(struct wl_client *client, struct wl_resource *resource)
|
||||||
wl_resource_destroy(resource);
|
{
|
||||||
|
wl_resource_destroy(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 在外部ipc客户端结束的时候会发出销毁请求,比如kill掉waybar,就会销毁waybar绑定的ipc_output
|
static void
|
||||||
static void dwl_ipc_output_destroy(struct wl_resource *resource) {
|
dwl_ipc_output_destroy(struct wl_resource *resource)
|
||||||
DwlIpcOutput *ipc_output = wl_resource_get_user_data(resource);
|
{
|
||||||
wl_list_remove(&ipc_output->link);
|
DwlIpcOutput *ipc_output = wl_resource_get_user_data(resource);
|
||||||
free(ipc_output);
|
wl_list_remove(&ipc_output->link);
|
||||||
|
free(ipc_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dwl_ipc_output_printstatus(Monitor *monitor) {
|
void
|
||||||
DwlIpcOutput *ipc_output;
|
dwl_ipc_output_printstatus(Monitor *monitor)
|
||||||
wl_list_for_each(ipc_output, &monitor->dwl_ipc_outputs, link)
|
{
|
||||||
dwl_ipc_output_printstatus_to(ipc_output);
|
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) {
|
void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
|
||||||
Monitor *monitor = ipc_output->monitor;
|
Monitor *monitor = ipc_output->mon;
|
||||||
Client *c, *focused;
|
Client *c, *focused;
|
||||||
int tagmask, state, numclients, focused_client, tag;
|
int tagmask, state, numclients, focused_client, tag;
|
||||||
const char *title, *appid, *symbol;
|
const char *title, *appid, *symbol;
|
||||||
|
|
@ -2928,30 +2931,29 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
|
||||||
|
|
||||||
// numclients++;
|
// numclients++;
|
||||||
// }
|
// }
|
||||||
// zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state,
|
// zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, numclients,
|
||||||
// numclients,
|
|
||||||
// focused_client);
|
// focused_client);
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
for (tag = 0; tag < LENGTH(tags); tag++) {
|
for ( tag = 0 ; tag < LENGTH(tags); tag++) {
|
||||||
numclients = state = focused_client = 0;
|
numclients = state = focused_client = 0;
|
||||||
tagmask = 1 << tag;
|
tagmask = 1 << tag;
|
||||||
if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
|
if ((tagmask & monitor->tagset[monitor->seltags]) != 0)
|
||||||
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE;
|
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE;
|
||||||
wl_list_for_each(c, &clients, link) {
|
wl_list_for_each(c, &clients, link) {
|
||||||
if (c->mon != monitor)
|
if (c->mon != monitor)
|
||||||
continue;
|
continue;
|
||||||
if (!(c->tags & tagmask))
|
if (!(c->tags & tagmask))
|
||||||
continue;
|
continue;
|
||||||
if (c == focused)
|
if (c == focused)
|
||||||
focused_client = 1;
|
focused_client = 1;
|
||||||
if (c->isurgent)
|
if (c->isurgent)
|
||||||
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT;
|
state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_URGENT;
|
||||||
numclients++;
|
numclients++;
|
||||||
}
|
}
|
||||||
zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state, numclients,
|
zdwl_ipc_output_v2_send_tag(ipc_output->resource, tag, state,
|
||||||
focused_client);
|
numclients, focused_client);
|
||||||
}
|
}
|
||||||
|
|
||||||
title = focused ? client_get_title(focused) : "";
|
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;
|
symbol = monitor->pertag->ltidxs[monitor->pertag->curtag]->symbol;
|
||||||
|
|
||||||
zdwl_ipc_output_v2_send_layout(
|
zdwl_ipc_output_v2_send_layout(
|
||||||
ipc_output->resource,
|
ipc_output->resource,
|
||||||
monitor->pertag->ltidxs[monitor->pertag->curtag] - layouts);
|
monitor->pertag->ltidxs[monitor->pertag->curtag] - layouts);
|
||||||
zdwl_ipc_output_v2_send_title(ipc_output->resource, title ? title : broken);
|
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_appid(ipc_output->resource, appid ? appid : broken);
|
||||||
zdwl_ipc_output_v2_send_layout_symbol(ipc_output->resource, symbol);
|
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,
|
void
|
||||||
struct wl_resource *resource,
|
dwl_ipc_output_set_client_tags(struct wl_client *client, struct wl_resource *resource, uint32_t and_tags, uint32_t xor_tags)
|
||||||
uint32_t and_tags, uint32_t xor_tags) {
|
{
|
||||||
DwlIpcOutput *ipc_output;
|
DwlIpcOutput *ipc_output;
|
||||||
Monitor *monitor;
|
Monitor *monitor;
|
||||||
Client *selected_client;
|
Client *selected_client;
|
||||||
unsigned int newtags = 0;
|
unsigned int newtags = 0;
|
||||||
|
|
||||||
ipc_output = wl_resource_get_user_data(resource);
|
ipc_output = wl_resource_get_user_data(resource);
|
||||||
if (!ipc_output)
|
if (!ipc_output)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
monitor = ipc_output->monitor;
|
monitor = ipc_output->mon;
|
||||||
selected_client = focustop(monitor);
|
selected_client = focustop(monitor);
|
||||||
if (!selected_client)
|
if (!selected_client)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
newtags = (selected_client->tags & and_tags) ^ xor_tags;
|
newtags = (selected_client->tags & and_tags) ^ xor_tags;
|
||||||
if (!newtags)
|
if (!newtags)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
selected_client->tags = newtags;
|
selected_client->tags = newtags;
|
||||||
focusclient(focustop(selmon), 1);
|
if (selmon == monitor)
|
||||||
arrange(selmon, true);
|
focusclient(focustop(monitor), 1);
|
||||||
printstatus();
|
arrange(selmon,false);
|
||||||
|
printstatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dwl_ipc_output_set_layout(struct wl_client *client,
|
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)
|
if (!ipc_output)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
monitor = ipc_output->monitor;
|
monitor = ipc_output->mon;
|
||||||
if (index >= LENGTH(layouts))
|
if (index >= LENGTH(layouts))
|
||||||
index = 0;
|
index = 0;
|
||||||
|
|
||||||
|
|
@ -3012,32 +3021,25 @@ void dwl_ipc_output_set_layout(struct wl_client *client,
|
||||||
printstatus();
|
printstatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void dwl_ipc_output_set_tags(struct wl_client *client,
|
void
|
||||||
struct wl_resource *resource, uint32_t tagmask,
|
dwl_ipc_output_set_tags(struct wl_client *client, struct wl_resource *resource, uint32_t tagmask, uint32_t toggle_tagset)
|
||||||
uint32_t toggle_tagset) {
|
{
|
||||||
DwlIpcOutput *ipc_output;
|
DwlIpcOutput *ipc_output;
|
||||||
Monitor *monitor;
|
Monitor *monitor;
|
||||||
unsigned int newtags = tagmask & TAGMASK;
|
unsigned int newtags = tagmask & TAGMASK;
|
||||||
|
|
||||||
ipc_output = wl_resource_get_user_data(resource);
|
ipc_output = wl_resource_get_user_data(resource);
|
||||||
if (!ipc_output)
|
if (!ipc_output)
|
||||||
return;
|
return;
|
||||||
monitor = ipc_output->monitor;
|
monitor = ipc_output->mon;
|
||||||
|
|
||||||
if (!newtags || newtags == monitor->tagset[monitor->seltags])
|
view_in_mon(&(Arg){.ui = newtags}, true,monitor);
|
||||||
return;
|
|
||||||
if (toggle_tagset)
|
|
||||||
monitor->seltags ^= 1;
|
|
||||||
|
|
||||||
monitor->tagset[monitor->seltags] = newtags;
|
|
||||||
focusclient(focustop(monitor), 1);
|
|
||||||
arrange(monitor, true);
|
|
||||||
printstatus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void dwl_ipc_output_release(struct wl_client *client,
|
void
|
||||||
struct wl_resource *resource) {
|
dwl_ipc_output_release(struct wl_client *client, struct wl_resource *resource)
|
||||||
wl_resource_destroy(resource);
|
{
|
||||||
|
wl_resource_destroy(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
void focusclient(Client *c, int lift) {
|
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 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;
|
size_t i, tmptag;
|
||||||
|
|
||||||
if (!selmon || (arg->ui != ~0 && selmon->isoverview)) {
|
if (!m || (arg->ui != ~0 && m->isoverview)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((selmon->tagset[selmon->seltags] & arg->ui & TAGMASK) != 0) {
|
if ((m->tagset[m->seltags] & arg->ui & TAGMASK) != 0) {
|
||||||
want_animation = false;
|
want_animation = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
selmon->seltags ^= 1; /* toggle sel tagset */
|
m->seltags ^= 1; /* toggle sel tagset */
|
||||||
if (arg->ui & TAGMASK) {
|
if (arg->ui & TAGMASK) {
|
||||||
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
|
m->tagset[m->seltags] = arg->ui & TAGMASK;
|
||||||
selmon->pertag->prevtag = selmon->pertag->curtag;
|
m->pertag->prevtag = m->pertag->curtag;
|
||||||
|
|
||||||
if (arg->ui == ~0)
|
if (arg->ui == ~0)
|
||||||
selmon->pertag->curtag = 0;
|
m->pertag->curtag = 0;
|
||||||
else {
|
else {
|
||||||
for (i = 0; !(arg->ui & 1 << i); i++)
|
for (i = 0; !(arg->ui & 1 << i); i++)
|
||||||
;
|
;
|
||||||
selmon->pertag->curtag = i + 1;
|
m->pertag->curtag = i + 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tmptag = selmon->pertag->prevtag;
|
tmptag = m->pertag->prevtag;
|
||||||
selmon->pertag->prevtag = selmon->pertag->curtag;
|
m->pertag->prevtag = m->pertag->curtag;
|
||||||
selmon->pertag->curtag = tmptag;
|
m->pertag->curtag = tmptag;
|
||||||
}
|
}
|
||||||
|
|
||||||
focusclient(focustop(selmon), 1);
|
focusclient(focustop(m), 1);
|
||||||
arrange(selmon, want_animation);
|
arrange(m, want_animation);
|
||||||
printstatus();
|
printstatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void view(const Arg *arg, bool want_animation) {
|
||||||
|
view_in_mon(arg, want_animation, selmon);
|
||||||
|
}
|
||||||
|
|
||||||
void viewtoleft(const Arg *arg) {
|
void viewtoleft(const Arg *arg) {
|
||||||
size_t tmptag;
|
size_t tmptag;
|
||||||
unsigned int target = selmon->tagset[selmon->seltags];
|
unsigned int target = selmon->tagset[selmon->seltags];
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ I would probably just submit raphi's patchset but I don't think that would be po
|
||||||
reset.
|
reset.
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<interface name="zdwl_ipc_manager_v2" version="1">
|
<interface name="zdwl_ipc_manager_v2" version="2">
|
||||||
<description summary="manage dwl state">
|
<description summary="manage dwl state">
|
||||||
This interface is exposed as a global in wl_registry.
|
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>
|
</event>
|
||||||
</interface>
|
</interface>
|
||||||
|
|
||||||
<interface name="zdwl_ipc_output_v2" version="1">
|
<interface name="zdwl_ipc_output_v2" version="2">
|
||||||
<description summary="control dwl output">
|
<description summary="control dwl output">
|
||||||
Observe and control a 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"/>
|
<description summary="Set the layout of this output"/>
|
||||||
<arg name="index" type="uint" summary="index of a layout recieved by dwl_ipc_manager.layout"/>
|
<arg name="index" type="uint" summary="index of a layout recieved by dwl_ipc_manager.layout"/>
|
||||||
</request>
|
</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>
|
</interface>
|
||||||
</protocol>
|
</protocol>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue