Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
move i3 sync code into sync_respond (for following commits)
Browse files Browse the repository at this point in the history
  • Loading branch information
stapelberg committed Mar 30, 2018
1 parent 4e0bf58 commit 725ee3c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Expand Up @@ -562,6 +562,7 @@ i3_SOURCES = \
src/sd-daemon.c \
src/sighandler.c \
src/startup.c \
src/sync.c \
src/tree.c \
src/util.c \
src/version.c \
Expand Down
1 change: 1 addition & 0 deletions include/all.h
Expand Up @@ -82,4 +82,5 @@
#include "fake_outputs.h"
#include "display_version.h"
#include "restore_layout.h"
#include "sync.h"
#include "main.h"
14 changes: 14 additions & 0 deletions include/sync.h
@@ -0,0 +1,14 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
*
* sync.c: i3 sync protocol: https://i3wm.org/docs/testsuite.html#i3_sync
*
*/
#pragma once

#include <xcb/xcb.h>

void sync_respond(xcb_window_t window, uint32_t rnd);
16 changes: 1 addition & 15 deletions src/handlers.c
Expand Up @@ -800,21 +800,7 @@ static void handle_client_message(xcb_client_message_event_t *event) {
} else if (event->type == A_I3_SYNC) {
xcb_window_t window = event->data.data32[0];
uint32_t rnd = event->data.data32[1];
DLOG("[i3 sync protocol] Sending random value %d back to X11 window 0x%08x\n", rnd, window);

void *reply = scalloc(32, 1);
xcb_client_message_event_t *ev = reply;

ev->response_type = XCB_CLIENT_MESSAGE;
ev->window = window;
ev->type = A_I3_SYNC;
ev->format = 32;
ev->data.data32[0] = window;
ev->data.data32[1] = rnd;

xcb_send_event(conn, false, window, XCB_EVENT_MASK_NO_EVENT, (char *)ev);
xcb_flush(conn);
free(reply);
sync_respond(window, rnd);
} else if (event->type == A__NET_REQUEST_FRAME_EXTENTS) {
/*
* A client can request an estimate for the frame size which the window
Expand Down
28 changes: 28 additions & 0 deletions src/sync.c
@@ -0,0 +1,28 @@
/*
* vim:ts=4:sw=4:expandtab
*
* i3 - an improved dynamic tiling window manager
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
*
* sync.c: i3 sync protocol: https://i3wm.org/docs/testsuite.html#i3_sync
*
*/
#include "all.h"

void sync_respond(xcb_window_t window, uint32_t rnd) {
DLOG("[i3 sync protocol] Sending random value %d back to X11 window 0x%08x\n", rnd, window);

void *reply = scalloc(32, 1);
xcb_client_message_event_t *ev = reply;

ev->response_type = XCB_CLIENT_MESSAGE;
ev->window = window;
ev->type = A_I3_SYNC;
ev->format = 32;
ev->data.data32[0] = window;
ev->data.data32[1] = rnd;

xcb_send_event(conn, false, window, XCB_EVENT_MASK_NO_EVENT, (char *)ev);
xcb_flush(conn);
free(reply);
}

0 comments on commit 725ee3c

Please sign in to comment.