-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wm: add wmc header for window manager clients
- Loading branch information
Showing
3 changed files
with
92 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#pragma once | ||
|
||
#include <syscalls.h> | ||
#include "wm.h" | ||
|
||
struct wmc_connection { | ||
int wm_control_fd; | ||
int win_fd_m, win_fd_s; | ||
}; | ||
|
||
int wmc_connection_init(struct wmc_connection *conn) { | ||
conn->wm_control_fd = open("/pipes/wm", 0); | ||
if(conn->wm_control_fd < 0) { | ||
return 0; | ||
} | ||
conn->win_fd_m = -1; | ||
conn->win_fd_s = -1; | ||
return 1; | ||
} | ||
|
||
void wmc_connection_deinit(struct wmc_connection *conn) { | ||
close(conn->wm_control_fd); | ||
close(conn->win_fd_m); | ||
close(conn->win_fd_s); | ||
} | ||
|
||
void wmc_connection_obtain(struct wmc_connection *conn) { | ||
struct wm_connection_request conn_req = { | ||
.pid = getpid() | ||
}; | ||
write(conn->wm_control_fd, (char *)&conn_req, sizeof(struct wm_connection_request)); | ||
while(1) { | ||
// try to poll for pipes | ||
char path[128] = { 0 }; | ||
|
||
if(conn->win_fd_m == -1) { | ||
snprintf(path, sizeof(path), "/pipes/wm:%d:m", conn_req.pid); | ||
if((conn->win_fd_m = open(path, 0)) < 0) { | ||
goto await_conn; | ||
} | ||
} | ||
|
||
if(conn->win_fd_s == -1) { | ||
snprintf(path, sizeof(path), "/pipes/wm:%d:s", conn_req.pid); | ||
if((conn->win_fd_s = open(path, 0)) < 0) { | ||
goto await_conn; | ||
} | ||
} | ||
|
||
if(conn->win_fd_m != -1 && conn->win_fd_s != -1) { | ||
break; | ||
} | ||
|
||
await_conn: | ||
usleep(1); | ||
} | ||
} | ||
|
||
int wmc_send_atom(struct wmc_connection *conn, struct wm_atom *atom) { | ||
return write(conn->win_fd_s, (char *)atom, sizeof(struct wm_atom)); | ||
} | ||
|
||
int wmc_recv_atom(struct wmc_connection *conn, struct wm_atom *atom) { | ||
return read(conn->win_fd_m, (char *)atom, sizeof(struct wm_atom)); | ||
} | ||
|
||
int wmc_wait_atom(struct wmc_connection *conn) { | ||
return waitfd(conn->win_fd_m, (useconds_t)-1); | ||
} |