Skip to content

Commit

Permalink
wm: request event masks on obtaining connection
Browse files Browse the repository at this point in the history
  • Loading branch information
ffwff committed Sep 8, 2019
1 parent 579a3bc commit 88f3075
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 42 deletions.
8 changes: 1 addition & 7 deletions pkgs/wm/canvwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int main(int argc, char **argv) {

struct wmc_connection conn;
wmc_connection_init(&conn);
wmc_connection_obtain(&conn);
wmc_connection_obtain(&conn, ATOM_MOUSE_EVENT_MASK);

// event loop
struct fbdev_bitblit sprite = {
Expand All @@ -103,12 +103,6 @@ int main(int argc, char **argv) {
.type = GFX_BITBLIT_SURFACE
};

struct wm_atom configure_atom = {
.type = ATOM_CONFIGURE_TYPE,
.configure.event_mask = ATOM_MOUSE_EVENT_MASK,
};
wmc_send_atom(&conn, &configure_atom);

int mouse_drag = 0;

struct wm_atom atom;
Expand Down
32 changes: 9 additions & 23 deletions pkgs/wm/wm.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,6 @@ struct wm_window *wm_add_sprite(struct wm_state *state, struct wm_window_sprite
return win;
}

void wm_handle_request_atom(struct wm_state *state, struct wm_window *win, struct wm_atom *atom) {
switch (atom->type) {
case ATOM_CONFIGURE_TYPE: {
win->as.prog.event_mask = atom->configure.event_mask;
}
}
}

/* IMPL */

int wm_sort_windows_by_z_compar(const void *av, const void *bv) {
Expand Down Expand Up @@ -190,7 +182,9 @@ int wm_handle_connection_request(struct wm_state *state, struct wm_connection_re
int sfd = create(path);
if(sfd < 0) { close(mfd); return 0; }

wm_add_win_prog(state, mfd, sfd);
struct wm_window *win = wm_add_win_prog(state, mfd, sfd);
win->as.prog.event_mask = conn_req->event_mask;

wm_sort_windows_by_z(state);
return 1;
}
Expand Down Expand Up @@ -265,7 +259,7 @@ int main(int argc, char **argv) {
while(1) {
{
// control pipe
struct wm_connection_request conn_req;
struct wm_connection_request conn_req = { 0 };
while(
read(control_fd, (char *)&conn_req, sizeof(struct wm_connection_request))
== sizeof(struct wm_connection_request)
Expand Down Expand Up @@ -327,20 +321,11 @@ int main(int argc, char **argv) {
int retval;
struct wm_atom respond_atom;

// read from queue
struct wm_atom req_atom;
while(
read(win->as.prog.sfd, (char *)&req_atom, sizeof(struct wm_atom))
== sizeof(struct wm_atom)
) {
wm_handle_request_atom(&wm, win, &req_atom);
}

// transmit events in queue
for(int i = 0; i < wm.queue_len; i++) {
// if((win->as.prog.event_mask & (1 << wm.queue[i].type)) != 0) {
if((win->as.prog.event_mask & (1 << wm.queue[i].type)) != 0) {
win_write_and_wait(&win->as.prog, &wm.queue[i], &respond_atom);
// }
}
}

// request a redraw
Expand All @@ -350,8 +335,9 @@ int main(int argc, char **argv) {
};
retval = win_write_and_wait(&win->as.prog, &redraw_atom, &respond_atom);

if (retval > 0) {
if (respond_atom.respond.retval)
if (retval == sizeof(struct wm_atom)) {
if (respond_atom.type == ATOM_RESPOND_TYPE &&
respond_atom.respond.retval)
wm.needs_redraw = 1;
}
break;
Expand Down
10 changes: 1 addition & 9 deletions pkgs/wm/wm.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
/* Connection request */
struct wm_connection_request {
pid_t pid;
unsigned int event_mask;
};

/* Atoms */

// Configure

struct wm_atom_configure {
unsigned long event_mask;
};

// Move

struct wm_atom_move {
Expand Down Expand Up @@ -53,21 +48,18 @@ struct wm_atom {
struct wm_atom_move move;
struct wm_atom_respond respond;
struct wm_atom_mouse_event mouse_event;
struct wm_atom_configure configure;
};
};

#define ATOM_REDRAW_TYPE 0
#define ATOM_RESPOND_TYPE 1
#define ATOM_MOVE_TYPE 2
#define ATOM_MOUSE_EVENT_TYPE 3
#define ATOM_CONFIGURE_TYPE 4

#define ATOM_REDRAW_MASK (1 << ATOM_REDRAW_TYPE)
#define ATOM_RESPOND_MASK (1 << ATOM_RESPOND_TYPE)
#define ATOM_MOVE_MASK (1 << ATOM_MOVE_TYPE)
#define ATOM_MOUSE_EVENT_MASK (1 << ATOM_MOUSE_EVENT_TYPE)
#define ATOM_CONFIGURE_MASK (1 << ATOM_CONFIGURE_TYPE)

static inline int wm_atom_eq(struct wm_atom *a, struct wm_atom *b) {
if(a->type != b->type)
Expand Down
11 changes: 8 additions & 3 deletions pkgs/wm/wmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ void wmc_connection_deinit(struct wmc_connection *conn) {
close(conn->win_fd_s);
}

void wmc_connection_obtain(struct wmc_connection *conn) {
void wmc_connection_obtain(struct wmc_connection *conn, unsigned int event_mask) {
struct wm_connection_request conn_req = {
.pid = getpid()
.pid = getpid(),
.event_mask = event_mask,
};
write(conn->wm_control_fd, (char *)&conn_req, sizeof(struct wm_connection_request));
while(1) {
Expand Down Expand Up @@ -61,7 +62,11 @@ int wmc_send_atom(struct wmc_connection *conn, struct wm_atom *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));
if(atom == NULL) {
struct wm_atom unused;
return read(conn->win_fd_m, (char *)&unused, sizeof(struct wm_atom));
}
return read(conn->win_fd_m, (char *)atom, sizeof(struct wm_atom));
}

int wmc_wait_atom(struct wmc_connection *conn) {
Expand Down

0 comments on commit 88f3075

Please sign in to comment.