mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-02-28 01:40:23 -05: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,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue