mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2025-10-29 05:40:21 -04:00
opt: mmsg add ack confirm
This commit is contained in:
parent
8f7d344de3
commit
a9e9ad905f
3 changed files with 75 additions and 0 deletions
45
mmsg/mmsg.c
45
mmsg/mmsg.c
|
|
@ -6,6 +6,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-util.h>
|
||||
|
||||
|
|
@ -56,6 +58,9 @@ static char *dispatch_arg3;
|
|||
static char *dispatch_arg4;
|
||||
static char *dispatch_arg5;
|
||||
|
||||
static int request_completed = 0;
|
||||
static uint32_t starttimestamp = 0;
|
||||
|
||||
struct output {
|
||||
char *output_name;
|
||||
uint32_t name;
|
||||
|
|
@ -296,6 +301,13 @@ static void dwl_ipc_output_floating(void *data,
|
|||
printf("floating %u\n", is_floating);
|
||||
}
|
||||
|
||||
static void dwl_ipc_output_askconfirm(void *data,
|
||||
struct zdwl_ipc_output_v2 *dwl_ipc_output,
|
||||
const uint32_t askconfirm) {
|
||||
request_completed = askconfirm;
|
||||
printf("askconfirm %d\n", askconfirm);
|
||||
}
|
||||
|
||||
static void dwl_ipc_output_frame(void *data,
|
||||
struct zdwl_ipc_output_v2 *dwl_ipc_output) {
|
||||
if (mode & SET) {
|
||||
|
|
@ -373,6 +385,38 @@ static void dwl_ipc_output_frame(void *data,
|
|||
dispatch_arg3, dispatch_arg4, dispatch_arg5);
|
||||
}
|
||||
wl_display_flush(display);
|
||||
struct timespec start;
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
starttimestamp = (uint32_t)(start.tv_sec * 1000 +
|
||||
start.tv_nsec / 1000000); // 毫秒时间戳
|
||||
|
||||
int display_fd = wl_display_get_fd(display);
|
||||
struct pollfd pfd = {.fd = display_fd, .events = POLLIN};
|
||||
|
||||
while (request_completed > starttimestamp) {
|
||||
// 非阻塞地检查事件
|
||||
wl_display_dispatch_pending(display);
|
||||
wl_display_flush(display);
|
||||
|
||||
if (request_completed)
|
||||
break;
|
||||
|
||||
// 使用poll等待事件,超时时间为1000毫秒
|
||||
int poll_ret = poll(&pfd, 1, 1000);
|
||||
if (poll_ret == 0) {
|
||||
fprintf(stderr, "CLIENT: Timeout waiting for confirmation\n");
|
||||
break;
|
||||
} else if (poll_ret < 0) {
|
||||
perror("poll");
|
||||
break;
|
||||
} else {
|
||||
// 有事件到达,调用wl_display_dispatch来处理事件
|
||||
if (wl_display_dispatch(display) < 0) {
|
||||
fprintf(stderr, "CLIENT: wl_display_dispatch failed\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
} else {
|
||||
if (tflag) {
|
||||
|
|
@ -411,6 +455,7 @@ static const struct zdwl_ipc_output_v2_listener dwl_ipc_output_listener = {
|
|||
.last_layer = dwl_ipc_output_last_layer,
|
||||
.kb_layout = dwl_ipc_output_kb_layout,
|
||||
.keymode = dwl_ipc_output_keymode,
|
||||
.askconfirm = dwl_ipc_output_askconfirm,
|
||||
.frame = dwl_ipc_output_frame,
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -241,6 +241,13 @@ I would probably just submit raphi's patchset but I don't think that would be po
|
|||
<arg name="keymode" type="string" summary="current keybind mode."/>
|
||||
</event>
|
||||
|
||||
<event name="askconfirm" since="2">
|
||||
<description summary="already receive the request.">
|
||||
already receive the request.
|
||||
</description>
|
||||
<arg name="askconfirm" type="uint" summary="already receive the request."/>
|
||||
</event>
|
||||
|
||||
</interface>
|
||||
|
||||
</protocol>
|
||||
|
|
|
|||
|
|
@ -207,6 +207,16 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) {
|
|||
zdwl_ipc_output_v2_send_frame(ipc_output->resource);
|
||||
}
|
||||
|
||||
void dwl_ipc_output_askconfirm(DwlIpcOutput *ipc_output) {
|
||||
// 发送当前时间戳而不是固定的1
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
uint32_t timestamp =
|
||||
(uint32_t)(ts.tv_sec * 1000 + ts.tv_nsec / 1000000); // 毫秒时间戳
|
||||
|
||||
zdwl_ipc_output_v2_send_askconfirm(ipc_output->resource, timestamp);
|
||||
}
|
||||
|
||||
void dwl_ipc_output_set_client_tags(struct wl_client *client,
|
||||
struct wl_resource *resource,
|
||||
unsigned int and_tags,
|
||||
|
|
@ -234,6 +244,7 @@ void dwl_ipc_output_set_client_tags(struct wl_client *client,
|
|||
focusclient(focustop(monitor), 1);
|
||||
arrange(selmon, false);
|
||||
printstatus();
|
||||
dwl_ipc_output_askconfirm(ipc_output);
|
||||
}
|
||||
|
||||
void dwl_ipc_output_set_layout(struct wl_client *client,
|
||||
|
|
@ -253,6 +264,7 @@ void dwl_ipc_output_set_layout(struct wl_client *client,
|
|||
monitor->pertag->ltidxs[monitor->pertag->curtag] = &layouts[index];
|
||||
arrange(monitor, false);
|
||||
printstatus();
|
||||
dwl_ipc_output_askconfirm(ipc_output);
|
||||
}
|
||||
|
||||
void dwl_ipc_output_set_tags(struct wl_client *client,
|
||||
|
|
@ -268,11 +280,17 @@ void dwl_ipc_output_set_tags(struct wl_client *client,
|
|||
monitor = ipc_output->mon;
|
||||
|
||||
view_in_mon(&(Arg){.ui = newtags}, true, monitor, true);
|
||||
dwl_ipc_output_askconfirm(ipc_output);
|
||||
}
|
||||
|
||||
void dwl_ipc_output_quit(struct wl_client *client,
|
||||
struct wl_resource *resource) {
|
||||
DwlIpcOutput *ipc_output;
|
||||
ipc_output = wl_resource_get_user_data(resource);
|
||||
if (!ipc_output)
|
||||
return;
|
||||
quit(&(Arg){0});
|
||||
dwl_ipc_output_askconfirm(ipc_output);
|
||||
}
|
||||
|
||||
void dwl_ipc_output_dispatch(struct wl_client *client,
|
||||
|
|
@ -283,6 +301,10 @@ void dwl_ipc_output_dispatch(struct wl_client *client,
|
|||
|
||||
int (*func)(const Arg *);
|
||||
Arg arg;
|
||||
DwlIpcOutput *ipc_output;
|
||||
ipc_output = wl_resource_get_user_data(resource);
|
||||
if (!ipc_output)
|
||||
return;
|
||||
func = parse_func_name((char *)dispatch, &arg, (char *)arg1, (char *)arg2,
|
||||
(char *)arg3, (char *)arg4, (char *)arg5);
|
||||
if (func) {
|
||||
|
|
@ -295,6 +317,7 @@ void dwl_ipc_output_dispatch(struct wl_client *client,
|
|||
free(arg.v2);
|
||||
if (arg.v3)
|
||||
free(arg.v3);
|
||||
dwl_ipc_output_askconfirm(ipc_output);
|
||||
}
|
||||
|
||||
void dwl_ipc_output_release(struct wl_client *client,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue