swc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/swc
Log | Files | Refs | README | LICENSE

commit cfb719d20e4c48fc2f7f5a4c35122f28667fead3
parent 0cac6819df94dce46184db40e49d6e2b56d9237b
Author: Michael Forney <mforney@mforney.org>
Date:   Mon, 18 May 2015 05:58:29 +0000

Fix up some style issues

Diffstat:
Mexample/wm.c | 4++--
Mlaunch/launch.c | 29++++++++++-------------------
Mlibswc/bindings.c | 41+++++++++++++++--------------------------
Mlibswc/compositor.c | 225++++++++++++++++++++++++++++++-------------------------------------------------
Mlibswc/compositor.h | 27+++++++++++----------------
Mlibswc/cursor_plane.c | 11+++++------
Mlibswc/cursor_plane.h | 4+---
Mlibswc/data.c | 61+++++++++++++++++++++++--------------------------------------
Mlibswc/data.h | 12+++---------
Mlibswc/data_device.c | 40+++++++++++++---------------------------
Mlibswc/data_device.h | 8++------
Mlibswc/data_device_manager.c | 31+++++++++++--------------------
Mlibswc/drm.c | 109++++++++++++++++++++++++++++---------------------------------------------------
Mlibswc/evdev_device.c | 101+++++++++++++++++++++++++++++++++++--------------------------------------------
Mlibswc/evdev_device.h | 14++++----------
Mlibswc/event.h | 26++++++++++++--------------
Mlibswc/framebuffer_plane.c | 39++++++++++++---------------------------
Mlibswc/framebuffer_plane.h | 6+-----
Mlibswc/input.c | 35+++++++++++------------------------
Mlibswc/input.h | 24++++++------------------
Mlibswc/keyboard.c | 80+++++++++++++++++++++++++++++--------------------------------------------------
Mlibswc/keyboard.h | 16+++++-----------
Mlibswc/launch.c | 16++++------------
Mlibswc/launch.h | 1-
Mlibswc/mode.c | 6++----
Mlibswc/mode.h | 1-
Mlibswc/output.c | 23++++++++++-------------
Mlibswc/panel.c | 73+++++++++++++++++++++++++++++--------------------------------------------
Mlibswc/panel.h | 9++++-----
Mlibswc/panel_manager.c | 24+++++++-----------------
Mlibswc/pointer.c | 138++++++++++++++++++++++++++++++++-----------------------------------------------
Mlibswc/pointer.h | 28+++++++++-------------------
Mlibswc/region.c | 30+++++++++---------------------
Mlibswc/region.h | 3+--
Mlibswc/screen.c | 43++++++++++++++++---------------------------
Mlibswc/screen.h | 13+++++--------
Mlibswc/seat.c | 150+++++++++++++++++++++++++++++++++++--------------------------------------------
Mlibswc/shell.c | 19++++++-------------
Mlibswc/shell_surface.c | 92++++++++++++++++++++++++++++---------------------------------------------------
Mlibswc/shell_surface.h | 4+---
Mlibswc/shm.c | 49++++++++++++++++---------------------------------
Mlibswc/shm.h | 1-
Mlibswc/subcompositor.c | 25+++++++++----------------
Mlibswc/subcompositor.h | 5++---
Mlibswc/subsurface.c | 35++++++++++++-----------------------
Mlibswc/subsurface.h | 3+--
Mlibswc/surface.c | 131+++++++++++++++++++++++++++----------------------------------------------------
Mlibswc/surface.h | 7++-----
Mlibswc/swc.c | 39++++++++++++++-------------------------
Mlibswc/swc.h | 129++++++++++++++++++++++++++++++++++++-------------------------------------------
Mlibswc/util.c | 3++-
Mlibswc/util.h | 12+++++-------
Mlibswc/view.c | 20++++++++------------
Mlibswc/view.h | 6++----
Mlibswc/wayland_buffer.c | 13++++---------
Mlibswc/wayland_buffer.h | 4+---
Mlibswc/window.c | 167+++++++++++++++++++++++++++++--------------------------------------------------
Mlibswc/window.h | 26++++++--------------------
Mlibswc/xdg_popup.c | 22+++++++---------------
Mlibswc/xdg_popup.h | 7++-----
Mlibswc/xdg_shell.c | 55+++++++++++++++++++------------------------------------
Mlibswc/xdg_surface.c | 98++++++++++++++++++++++++++++---------------------------------------------------
Mlibswc/xdg_surface.h | 4+---
Mlibswc/xkb.c | 9+++------
Mlibswc/xkb.h | 7++-----
Mlibswc/xserver.c | 37++++++++++++++-----------------------
Mlibswc/xwm.c | 104+++++++++++++++++++++++++++++++++----------------------------------------------
67 files changed, 975 insertions(+), 1659 deletions(-)

diff --git a/example/wm.c b/example/wm.c @@ -131,8 +131,8 @@ screen_usable_geometry_changed(void *data) struct screen *screen = data; /* If the usable geometry of the screen changes, for example when a panel is - * docked to the edge of the screen, we need to rearrange the windows to - * ensure they are all within the new usable geometry. */ + * docked to the edge of the screen, we need to rearrange the windows to + * ensure they are all within the new usable geometry. */ arrange(screen); } diff --git a/launch/launch.c b/launch/launch.c @@ -55,8 +55,7 @@ pid_t child_pid = -1; -static struct - { +static struct { int socket; int input_fds[128]; unsigned num_input_fds; @@ -66,8 +65,7 @@ static struct bool active; } launcher; -static struct - { +static struct { bool altered; int vt; long kb_mode; @@ -109,12 +107,10 @@ stop_devices(bool fatal) } for (index = 0; index < launcher.num_input_fds; ++index) { - if (ioctl(launcher.input_fds[index], EVIOCREVOKE, 0) == -1 - && errno != ENODEV && fatal) { + if (ioctl(launcher.input_fds[index], EVIOCREVOKE, 0) == -1 && errno != ENODEV && fatal) die("FATAL: Your kernel does not support EVIOCREVOKE; " "input devices cannot be revoked: %s", strerror(errno)); - } close(launcher.input_fds[index]); } @@ -136,8 +132,8 @@ cleanup(void) ioctl(launcher.tty_fd, KDSETMODE, original_vt_state.console_mode); ioctl(launcher.tty_fd, KDSKBMODE, original_vt_state.kb_mode); - /* Stop devices before switching the VT to make sure we have released the - * DRM device before the next session tries to claim it. */ + /* Stop devices before switching the VT to make sure we have released the DRM + * device before the next session tries to claim it. */ stop_devices(false); ioctl(launcher.tty_fd, VT_ACTIVATE, original_vt_state.vt); @@ -236,8 +232,7 @@ handle_socket_data(int socket) switch (request->type) { case SWC_LAUNCH_REQUEST_OPEN_DEVICE: - if (request->path[size - __builtin_offsetof(typeof(*request), - path) - 1] != '\0') { + if (request->path[size - __builtin_offsetof(typeof(*request), path) - 1] != '\0') { fprintf(stderr, "Path is not NULL terminated\n"); goto fail; } @@ -252,15 +247,13 @@ handle_socket_data(int socket) if (!launcher.active) goto fail; - if (launcher.num_input_fds - == ARRAY_LENGTH(launcher.input_fds)) { + if (launcher.num_input_fds == ARRAY_LENGTH(launcher.input_fds)) { fprintf(stderr, "Too many input devices opened\n"); goto fail; } break; case DRM_MAJOR: - if (launcher.num_drm_fds - == ARRAY_LENGTH(launcher.drm_fds)) { + if (launcher.num_drm_fds == ARRAY_LENGTH(launcher.drm_fds)) { fprintf(stderr, "Too many DRM devices opened\n"); goto fail; } @@ -291,10 +284,8 @@ handle_socket_data(int socket) if (!launcher.active) goto fail; - if (ioctl(launcher.tty_fd, VT_ACTIVATE, request->vt) == -1) { - fprintf(stderr, "Could not activate VT %d: %s\n", - request->vt, strerror(errno)); - } + if (ioctl(launcher.tty_fd, VT_ACTIVATE, request->vt) == -1) + fprintf(stderr, "Could not activate VT %d: %s\n", request->vt, strerror(errno)); break; default: fprintf(stderr, "Unknown request %u\n", request->type); diff --git a/libswc/bindings.c b/libswc/bindings.c @@ -39,38 +39,33 @@ struct binding { void *data; }; -static bool handle_key(struct keyboard *keyboard, uint32_t time, - struct key *key, uint32_t state); +static bool handle_key(struct keyboard *keyboard, uint32_t time, struct key *key, uint32_t state); static struct keyboard_handler key_binding_handler = { - .key = &handle_key + .key = handle_key, }; -static bool handle_button(struct pointer_handler *handler, uint32_t time, - struct button *button, uint32_t state); +static bool handle_button(struct pointer_handler *handler, uint32_t time, struct button *button, uint32_t state); static struct pointer_handler button_binding_handler = { - .button = &handle_button + .button = handle_button, }; static struct wl_array key_bindings, button_bindings; const struct swc_bindings swc_bindings = { .keyboard_handler = &key_binding_handler, - .pointer_handler = &button_binding_handler + .pointer_handler = &button_binding_handler, }; static struct binding * -find_binding(struct wl_array *bindings, - uint32_t modifiers, uint32_t value) +find_binding(struct wl_array *bindings, uint32_t modifiers, uint32_t value) { struct binding *binding; wl_array_for_each (binding, bindings) { - if (binding->value == value && (binding->modifiers == modifiers - || binding->modifiers == SWC_MOD_ANY)) { + if (binding->value == value && (binding->modifiers == modifiers || binding->modifiers == SWC_MOD_ANY)) return binding; - } } return NULL; @@ -95,8 +90,7 @@ find_key_binding(uint32_t modifiers, uint32_t key) /* Then try the keysym associated with shift-level 0 for the key. */ layout = xkb_state_key_get_layout(xkb->state, XKB_KEY(key)); - xkb_keymap_key_get_syms_by_level(xkb->keymap.map, XKB_KEY(key), - layout, 0, &keysyms); + xkb_keymap_key_get_syms_by_level(xkb->keymap.map, XKB_KEY(key), layout, 0, &keysyms); if (!keysyms) return NULL; @@ -113,8 +107,7 @@ find_button_binding(uint32_t modifiers, uint32_t value) } static bool -handle_binding(uint32_t time, struct press *press, uint32_t state, - struct binding *(*find_binding)(uint32_t, uint32_t)) +handle_binding(uint32_t time, struct press *press, uint32_t state, struct binding *(*find_binding)(uint32_t, uint32_t)) { struct binding *binding; @@ -125,8 +118,9 @@ handle_binding(uint32_t time, struct press *press, uint32_t state, return false; press->data = binding; - } else + } else { binding = press->data; + } binding->handler(binding->data, time, binding->value, state); @@ -134,15 +128,13 @@ handle_binding(uint32_t time, struct press *press, uint32_t state, } bool -handle_key(struct keyboard *keyboard, uint32_t time, - struct key *key, uint32_t state) +handle_key(struct keyboard *keyboard, uint32_t time, struct key *key, uint32_t state) { return handle_binding(time, &key->press, state, &find_key_binding); } bool -handle_button(struct pointer_handler *handler, uint32_t time, - struct button *button, uint32_t state) +handle_button(struct pointer_handler *handler, uint32_t time, struct button *button, uint32_t state) { return handle_binding(time, &button->press, state, &find_button_binding); } @@ -163,11 +155,8 @@ bindings_finalize(void) wl_array_release(&button_bindings); } -EXPORT -int -swc_add_binding(enum swc_binding_type type, - uint32_t modifiers, uint32_t value, - swc_binding_handler handler, void *data) +EXPORT int +swc_add_binding(enum swc_binding_type type, uint32_t modifiers, uint32_t value, swc_binding_handler handler, void *data) { struct binding *binding; struct wl_array *bindings; diff --git a/libswc/compositor.c b/libswc/compositor.c @@ -62,26 +62,22 @@ struct target { struct wl_listener screen_destroy_listener; }; -static bool handle_motion(struct pointer_handler *handler, uint32_t time, - wl_fixed_t x, wl_fixed_t y); +static bool handle_motion(struct pointer_handler *handler, uint32_t time, wl_fixed_t x, wl_fixed_t y); static void perform_update(void *data); static struct pointer_handler pointer_handler = { - .motion = &handle_motion + .motion = handle_motion, }; -static struct - { +static struct { struct wl_list views; pixman_region32_t damage, opaque; struct wl_listener swc_listener; - /* A mask of screens that have been repainted but are waiting on a page - * flip. */ + /* A mask of screens that have been repainted but are waiting on a page flip. */ uint32_t pending_flips; - /* A mask of screens that are scheduled to be repainted on the next - * idle. */ + /* A mask of screens that are scheduled to be repainted on the next idle. */ uint32_t scheduled_updates; bool updating; @@ -89,7 +85,7 @@ static struct } compositor; struct swc_compositor swc_compositor = { - .pointer_handler = &pointer_handler + .pointer_handler = &pointer_handler, }; static void @@ -107,8 +103,7 @@ target_get(struct screen *screen) struct wl_listener *listener = wl_signal_get(&screen->destroy_signal, &handle_screen_destroy); struct target *target; - return listener ? wl_container_of(listener, target, screen_destroy_listener) - : NULL; + return listener ? wl_container_of(listener, target, screen_destroy_listener) : NULL; } static void @@ -129,16 +124,16 @@ handle_screen_frame(struct view_handler *handler, uint32_t time) target->current_buffer = target->next_buffer; - /* If we had scheduled updates that couldn't run because we were - * waiting on a page flip, run them now. If the compositor is - * currently updating, then the frame finished immediately, and we - * can be sure that there are no pending updates. */ + /* If we had scheduled updates that couldn't run because we were waiting on a + * page flip, run them now. If the compositor is currently updating, then the + * frame finished immediately, and we can be sure that there are no pending + * updates. */ if (compositor.scheduled_updates && !compositor.updating) perform_update(NULL); } static const struct view_handler_impl screen_view_handler = { - .frame = &handle_screen_frame, + .frame = handle_screen_frame, }; static int @@ -152,15 +147,12 @@ static struct target * target_new(struct screen *screen) { struct target *target; + struct swc_rectangle *geom = &screen->base.geometry; if (!(target = malloc(sizeof *target))) goto error0; - target->surface = wld_create_surface(swc.drm->context, - screen->base.geometry.width, - screen->base.geometry.height, - WLD_FORMAT_XRGB8888, - WLD_DRM_FLAG_SCANOUT); + target->surface = wld_create_surface(swc.drm->context, geom->width, geom->height, WLD_FORMAT_XRGB8888, WLD_DRM_FLAG_SCANOUT); if (!target->surface) goto error1; @@ -185,17 +177,15 @@ error0: /* Rendering {{{ */ static void -repaint_view(struct target *target, struct compositor_view *view, - pixman_region32_t *damage) +repaint_view(struct target *target, struct compositor_view *view, pixman_region32_t *damage) { pixman_region32_t view_region, view_damage, border_damage; - const struct swc_rectangle *geometry = &view->base.geometry; + const struct swc_rectangle *geom = &view->base.geometry, *target_geom = &target->view->geometry; if (!view->base.buffer) return; - pixman_region32_init_rect(&view_region, geometry->x, geometry->y, - geometry->width, geometry->height); + pixman_region32_init_rect(&view_region, geom->x, geom->y, geom->width, geom->height); pixman_region32_init_with_extents(&view_damage, &view->extents); pixman_region32_init(&border_damage); @@ -207,19 +197,15 @@ repaint_view(struct target *target, struct compositor_view *view, pixman_region32_fini(&view_region); if (pixman_region32_not_empty(&view_damage)) { - pixman_region32_translate(&view_damage, -geometry->x, -geometry->y); - wld_copy_region(swc.drm->renderer, view->buffer, - geometry->x - target->view->geometry.x, - geometry->y - target->view->geometry.y, &view_damage); + pixman_region32_translate(&view_damage, -geom->x, -geom->y); + wld_copy_region(swc.drm->renderer, view->buffer, geom->x - target_geom->x, geom->y - target_geom->y, &view_damage); } pixman_region32_fini(&view_damage); /* Draw border */ if (pixman_region32_not_empty(&border_damage)) { - pixman_region32_translate(&border_damage, - -target->view->geometry.x, - -target->view->geometry.y); + pixman_region32_translate(&border_damage, -target_geom->x, -target_geom->y); wld_fill_region(swc.drm->renderer, view->border.color, &border_damage); } @@ -227,10 +213,7 @@ repaint_view(struct target *target, struct compositor_view *view, } static void -renderer_repaint(struct target *target, - pixman_region32_t *damage, - pixman_region32_t *base_damage, - struct wl_list *views) +renderer_repaint(struct target *target, pixman_region32_t *damage, pixman_region32_t *base_damage, struct wl_list *views) { struct compositor_view *view; @@ -242,9 +225,7 @@ renderer_repaint(struct target *target, /* Paint base damage black. */ if (pixman_region32_not_empty(base_damage)) { - pixman_region32_translate(base_damage, - -target->view->geometry.x, - -target->view->geometry.y); + pixman_region32_translate(base_damage, -target->view->geometry.x, -target->view->geometry.y); wld_fill_region(swc.drm->renderer, 0xff000000, base_damage); } @@ -257,28 +238,20 @@ renderer_repaint(struct target *target, } static int -renderer_attach(struct compositor_view *view, - struct wld_buffer *client_buffer) +renderer_attach(struct compositor_view *view, struct wld_buffer *client_buffer) { struct wld_buffer *buffer; bool was_proxy = view->buffer != view->base.buffer; - bool needs_proxy = client_buffer - && !(wld_capabilities(swc.drm->renderer, - client_buffer) & WLD_CAPABILITY_READ); - bool resized = view->buffer && client_buffer - && (view->buffer->width != client_buffer->width - || view->buffer->height != client_buffer->height); + bool needs_proxy = client_buffer && !(wld_capabilities(swc.drm->renderer, client_buffer) & WLD_CAPABILITY_READ); + bool resized = view->buffer && client_buffer && (view->buffer->width != client_buffer->width || view->buffer->height != client_buffer->height); if (client_buffer) { - /* Create a proxy buffer if necessary (for example a hardware buffer - * backing a SHM buffer). */ + /* Create a proxy buffer if necessary (for example a hardware buffer backing + * a SHM buffer). */ if (needs_proxy) { if (!was_proxy || resized) { DEBUG("Creating a proxy buffer\n"); - buffer = wld_create_buffer(swc.drm->context, - client_buffer->width, - client_buffer->height, - client_buffer->format, WLD_FLAG_MAP); + buffer = wld_create_buffer(swc.drm->context, client_buffer->width, client_buffer->height, client_buffer->format, WLD_FLAG_MAP); if (!buffer) return -ENOMEM; @@ -286,17 +259,17 @@ renderer_attach(struct compositor_view *view, /* Otherwise we can keep the original proxy buffer. */ buffer = view->buffer; } - } else + } else { buffer = client_buffer; - } else + } + } else { buffer = NULL; + } /* If we no longer need a proxy buffer, or the original buffer is of a - * different size, destroy the old proxy image. */ - if (view->buffer && ((!needs_proxy && was_proxy) - || (needs_proxy && resized))) { + * different size, destroy the old proxy image. */ + if (view->buffer && ((!needs_proxy && was_proxy) || (needs_proxy && resized))) wld_buffer_unreference(view->buffer); - } view->buffer = buffer; @@ -310,8 +283,7 @@ renderer_flush_view(struct compositor_view *view) return; wld_set_target_buffer(swc.shm->renderer, view->buffer); - wld_copy_region(swc.shm->renderer, view->base.buffer, - 0, 0, &view->surface->state.damage); + wld_copy_region(swc.shm->renderer, view->base.buffer, 0, 0, &view->surface->state.damage); wld_flush(swc.shm->renderer); } @@ -330,8 +302,7 @@ damage_below_view(struct compositor_view *view) pixman_region32_init_with_extents(&damage_below, &view->extents); pixman_region32_subtract(&damage_below, &damage_below, &view->clip); - pixman_region32_union(&compositor.damage, &compositor.damage, - &damage_below); + pixman_region32_union(&compositor.damage, &compositor.damage, &damage_below); pixman_region32_fini(&damage_below); } @@ -350,10 +321,8 @@ update_extents(struct compositor_view *view) { view->extents.x1 = view->base.geometry.x - view->border.width; view->extents.y1 = view->base.geometry.y - view->border.width; - view->extents.x2 = view->base.geometry.x + view->base.geometry.width - + view->border.width; - view->extents.y2 = view->base.geometry.y + view->base.geometry.height - + view->border.width; + view->extents.x2 = view->base.geometry.x + view->base.geometry.width + view->border.width; + view->extents.y2 = view->base.geometry.y + view->base.geometry.height + view->border.width; /* Damage border. */ view->border.damaged = true; @@ -430,8 +399,8 @@ move(struct view *base, int32_t x, int32_t y) update_extents(view); if (view->visible) { - /* Assume worst-case no clipping until we draw the next frame (in - * case the surface gets moved again before that). */ + /* Assume worst-case no clipping until we draw the next frame (in case the + * surface gets moved again before that). */ pixman_region32_init(&view->clip); view_update_screens(&view->base); @@ -444,9 +413,9 @@ move(struct view *base, int32_t x, int32_t y) } const static struct view_impl view_impl = { - .update = &update, - .attach = &attach, - .move = &move + .update = update, + .attach = attach, + .move = move, }; struct compositor_view * @@ -499,8 +468,7 @@ compositor_view(struct view *view) } void -compositor_view_set_parent(struct compositor_view *view, - struct compositor_view *parent) +compositor_view_set_parent(struct compositor_view *view, struct compositor_view *parent) { view->parent = view; @@ -522,7 +490,7 @@ compositor_view_show(struct compositor_view *view) view_update_screens(&view->base); /* Assume worst-case no clipping until we draw the next frame (in case the - * surface gets moved before that. */ + * surface gets moved before that. */ pixman_region32_clear(&view->clip); damage_view(view); update(&view->base); @@ -555,8 +523,7 @@ compositor_view_hide(struct compositor_view *view) } void -compositor_view_set_border_width(struct compositor_view *view, - uint32_t width) +compositor_view_set_border_width(struct compositor_view *view, uint32_t width) { if (view->border.width == width) return; @@ -571,8 +538,7 @@ compositor_view_set_border_width(struct compositor_view *view, } void -compositor_view_set_border_color(struct compositor_view *view, - uint32_t color) +compositor_view_set_border_color(struct compositor_view *view, uint32_t color) { if (view->border.color == color) return; @@ -591,6 +557,7 @@ static void calculate_damage(void) { struct compositor_view *view; + struct swc_rectangle *geom; pixman_region32_t surface_opaque, *surface_damage; pixman_region32_clear(&compositor.opaque); @@ -601,18 +568,17 @@ calculate_damage(void) if (!view->visible) continue; + geom = &view->base.geometry; + /* Clip the surface by the opaque region covering it. */ pixman_region32_copy(&view->clip, &compositor.opaque); /* Translate the opaque region to global coordinates. */ pixman_region32_copy(&surface_opaque, &view->surface->state.opaque); - pixman_region32_translate(&surface_opaque, - view->base.geometry.x, view->base.geometry.y); + pixman_region32_translate(&surface_opaque, geom->x, geom->y); - /* Add the surface's opaque region to the accumulated opaque - * region. */ - pixman_region32_union(&compositor.opaque, &compositor.opaque, - &surface_opaque); + /* Add the surface's opaque region to the accumulated opaque region. */ + pixman_region32_union(&compositor.opaque, &compositor.opaque, &surface_opaque); surface_damage = &view->surface->state.damage; @@ -620,11 +586,10 @@ calculate_damage(void) renderer_flush_view(view); /* Translate surface damage to global coordinates. */ - pixman_region32_translate(surface_damage, view->base.geometry.x, view->base.geometry.y); + pixman_region32_translate(surface_damage, geom->x, geom->y); /* Add the surface damage to the compositor damage. */ - pixman_region32_union(&compositor.damage, &compositor.damage, - surface_damage); + pixman_region32_union(&compositor.damage, &compositor.damage, surface_damage); pixman_region32_clear(surface_damage); } @@ -632,14 +597,11 @@ calculate_damage(void) pixman_region32_t border_region, view_region; pixman_region32_init_with_extents(&border_region, &view->extents); - pixman_region32_init_rect(&view_region, view->base.geometry.x, view->base.geometry.y, - view->base.geometry.width, view->base.geometry.height); + pixman_region32_init_rect(&view_region, geom->x, geom->y, geom->width, geom->height); - pixman_region32_subtract(&border_region, &border_region, - &view_region); + pixman_region32_subtract(&border_region, &border_region, &view_region); - pixman_region32_union(&compositor.damage, &compositor.damage, - &border_region); + pixman_region32_union(&compositor.damage, &compositor.damage, &border_region); pixman_region32_fini(&border_region); pixman_region32_fini(&view_region); @@ -655,7 +617,7 @@ static void update_screen(struct screen *screen) { struct target *target; - const struct swc_rectangle *geometry = &screen->base.geometry; + const struct swc_rectangle *geom = &screen->base.geometry; pixman_region32_t damage, *total_damage; if (!(compositor.scheduled_updates & screen_mask(screen))) @@ -665,10 +627,8 @@ update_screen(struct screen *screen) return; pixman_region32_init(&damage); - pixman_region32_intersect_rect(&damage, &compositor.damage, - geometry->x, geometry->y, - geometry->width, geometry->height); - pixman_region32_translate(&damage, -geometry->x, -geometry->y); + pixman_region32_intersect_rect(&damage, &compositor.damage, geom->x, geom->y, geom->width, geom->height); + pixman_region32_translate(&damage, -geom->x, -geom->y); total_damage = wld_surface_damage(target->surface, &damage); /* Don't repaint the screen if it is waiting for a page flip. */ @@ -679,7 +639,7 @@ update_screen(struct screen *screen) pixman_region32_t base_damage; pixman_region32_copy(&damage, total_damage); - pixman_region32_translate(&damage, geometry->x, geometry->y); + pixman_region32_translate(&damage, geom->x, geom->y); pixman_region32_init(&base_damage); pixman_region32_subtract(&base_damage, &damage, &compositor.opaque); renderer_repaint(target, &damage, &base_damage, &compositor.views); @@ -688,9 +648,8 @@ update_screen(struct screen *screen) switch (target_swap_buffers(target)) { case -EACCES: - /* If we get an EACCES, it is because this session is being - * deactivated, but we haven't yet received the deactivate signal - * from swc-launch. */ + /* If we get an EACCES, it is because this session is being deactivated, but + * we haven't yet received the deactivate signal from swc-launch. */ swc_deactivate(); break; case 0: @@ -703,8 +662,7 @@ static void perform_update(void *data) { struct screen *screen; - uint32_t updates = compositor.scheduled_updates - & ~compositor.pending_flips; + uint32_t updates = compositor.scheduled_updates & ~compositor.pending_flips; if (!swc.active || !updates) return; @@ -724,23 +682,22 @@ perform_update(void *data) } bool -handle_motion(struct pointer_handler *handler, uint32_t time, - wl_fixed_t fx, wl_fixed_t fy) +handle_motion(struct pointer_handler *handler, uint32_t time, wl_fixed_t fx, wl_fixed_t fy) { struct compositor_view *view; bool found = false; int32_t x = wl_fixed_to_int(fx), y = wl_fixed_to_int(fy); + struct swc_rectangle *geom; wl_list_for_each (view, &compositor.views, link) { if (!view->visible) continue; - - if (rectangle_contains_point(&view->base.geometry, x, y) - && pixman_region32_contains_point(&view->surface->state.input, - x - view->base.geometry.x, - y - view->base.geometry.y, NULL)) { - found = true; - break; + geom = &view->base.geometry; + if (rectangle_contains_point(geom, x, y)) { + if (pixman_region32_contains_point(&view->surface->state.input, x - geom->x, y - geom->y, NULL)) { + found = true; + break; + } } } @@ -750,16 +707,14 @@ handle_motion(struct pointer_handler *handler, uint32_t time, } static void -handle_terminate(void *data, uint32_t time, - uint32_t value, uint32_t state) +handle_terminate(void *data, uint32_t time, uint32_t value, uint32_t state) { if (state == WL_KEYBOARD_KEY_STATE_PRESSED) wl_display_terminate(swc.display); } static void -handle_switch_vt(void *data, uint32_t time, - uint32_t value, uint32_t state) +handle_switch_vt(void *data, uint32_t time, uint32_t value, uint32_t state) { uint8_t vt = value - XKB_KEY_XF86Switch_VT_1 + 1; @@ -783,8 +738,7 @@ handle_swc_event(struct wl_listener *listener, void *data) } static void -create_surface(struct wl_client *client, - struct wl_resource *resource, uint32_t id) +create_surface(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct surface *surface; @@ -800,8 +754,7 @@ create_surface(struct wl_client *client, } static void -create_region(struct wl_client *client, - struct wl_resource *resource, uint32_t id) +create_region(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct region *region; @@ -812,23 +765,20 @@ create_region(struct wl_client *client, } static struct wl_compositor_interface compositor_implementation = { - .create_surface = &create_surface, - .create_region = &create_region + .create_surface = create_surface, + .create_region = create_region, }; static void -bind_compositor(struct wl_client *client, void *data, - uint32_t version, uint32_t id) +bind_compositor(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wl_resource *resource; if (version > 3) version = 3; - resource = wl_resource_create(client, &wl_compositor_interface, - version, id); - wl_resource_set_implementation(resource, &compositor_implementation, - NULL, NULL); + resource = wl_resource_create(client, &wl_compositor_interface, version, id); + wl_resource_set_implementation(resource, &compositor_implementation, NULL, NULL); } bool @@ -857,15 +807,10 @@ compositor_initialize(void) if (swc.active) schedule_updates(-1); - swc_add_binding(SWC_BINDING_KEY, SWC_MOD_CTRL | SWC_MOD_ALT, - XKB_KEY_BackSpace, &handle_terminate, NULL); + swc_add_binding(SWC_BINDING_KEY, SWC_MOD_CTRL | SWC_MOD_ALT, XKB_KEY_BackSpace, &handle_terminate, NULL); - for (keysym = XKB_KEY_XF86Switch_VT_1; - keysym <= XKB_KEY_XF86Switch_VT_12; - ++keysym) { - swc_add_binding(SWC_BINDING_KEY, SWC_MOD_ANY, keysym, - &handle_switch_vt, NULL); - } + for (keysym = XKB_KEY_XF86Switch_VT_1; keysym <= XKB_KEY_XF86Switch_VT_12; ++keysym) + swc_add_binding(SWC_BINDING_KEY, SWC_MOD_ANY, keysym, &handle_switch_vt, NULL); return true; } diff --git a/libswc/compositor.h b/libswc/compositor.h @@ -31,14 +31,13 @@ struct swc_compositor { struct pointer_handler *const pointer_handler; - struct - { + struct { /** - * Emitted when a new surface is created. - * - * The data argument of the signal refers to the surface that has been - * created. - */ + * Emitted when a new surface is created. + * + * The data argument of the signal refers to the surface that has been + * created. + */ struct wl_signal new_surface; } signal; }; @@ -60,11 +59,10 @@ struct compositor_view { pixman_box32_t extents; /* The region that is covered by opaque regions of surfaces above this - * surface. */ + * surface. */ pixman_region32_t clip; - struct - { + struct { uint32_t width; uint32_t color; bool damaged; @@ -83,15 +81,12 @@ void compositor_view_destroy(struct compositor_view *view); */ struct compositor_view *compositor_view(struct view *view); -void compositor_view_set_parent(struct compositor_view *view, - struct compositor_view *parent); +void compositor_view_set_parent(struct compositor_view *view, struct compositor_view *parent); void compositor_view_show(struct compositor_view *view); void compositor_view_hide(struct compositor_view *view); -void compositor_view_set_border_color(struct compositor_view *view, - uint32_t color); -void compositor_view_set_border_width(struct compositor_view *view, - uint32_t width); +void compositor_view_set_border_color(struct compositor_view *view, uint32_t color); +void compositor_view_set_border_width(struct compositor_view *view, uint32_t width); #endif diff --git a/libswc/cursor_plane.c b/libswc/cursor_plane.c @@ -51,7 +51,7 @@ attach(struct view *view, struct wld_buffer *buffer) if (!wld_export(buffer, WLD_DRM_OBJECT_HANDLE, &object)) { ERROR("Could not get export buffer to DRM handle\n"); /* XXX: Not the best error code, but we don't know better until wld - * returns an actual error code. */ + * returns an actual error code. */ return -EINVAL; } @@ -84,9 +84,9 @@ move(struct view *view, int32_t x, int32_t y) } static const struct view_impl view_impl = { - .update = &update, - .attach = &attach, - .move = &move + .update = update, + .attach = attach, + .move = move, }; static void @@ -104,8 +104,7 @@ handle_swc_event(struct wl_listener *listener, void *data) } bool -cursor_plane_initialize(struct cursor_plane *plane, uint32_t crtc, - const struct swc_rectangle *origin) +cursor_plane_initialize(struct cursor_plane *plane, uint32_t crtc, const struct swc_rectangle *origin) { plane->origin = origin; plane->crtc = crtc; diff --git a/libswc/cursor_plane.h b/libswc/cursor_plane.h @@ -33,9 +33,7 @@ struct cursor_plane { struct wl_listener swc_listener; }; -bool cursor_plane_initialize(struct cursor_plane *plane, uint32_t crtc, - const struct swc_rectangle *origin); - +bool cursor_plane_initialize(struct cursor_plane *plane, uint32_t crtc, const struct swc_rectangle *origin); void cursor_plane_finalize(struct cursor_plane *plane); #endif diff --git a/libswc/data.c b/libswc/data.c @@ -36,9 +36,7 @@ struct data { }; static void -offer_accept(struct wl_client *client, - struct wl_resource *offer, - uint32_t serial, const char *mime_type) +offer_accept(struct wl_client *client, struct wl_resource *offer, uint32_t serial, const char *mime_type) { struct data *data = wl_resource_get_user_data(offer); @@ -50,9 +48,7 @@ offer_accept(struct wl_client *client, } static void -offer_receive(struct wl_client *client, - struct wl_resource *offer, - const char *mime_type, int fd) +offer_receive(struct wl_client *client, struct wl_resource *offer, const char *mime_type, int fd) { struct data *data = wl_resource_get_user_data(offer); @@ -65,22 +61,19 @@ offer_receive(struct wl_client *client, } static void -offer_destroy(struct wl_client *client, - struct wl_resource *offer) +offer_destroy(struct wl_client *client, struct wl_resource *offer) { wl_resource_destroy(offer); } static struct wl_data_offer_interface data_offer_implementation = { - .accept = &offer_accept, - .receive = &offer_receive, - .destroy = &offer_destroy + .accept = offer_accept, + .receive = offer_receive, + .destroy = offer_destroy, }; static void -source_offer(struct wl_client *client, - struct wl_resource *source, - const char *mime_type) +source_offer(struct wl_client *client, struct wl_resource *source, const char *mime_type) { struct data *data = wl_resource_get_user_data(source); char **destination; @@ -90,15 +83,14 @@ source_offer(struct wl_client *client, } static void -source_destroy(struct wl_client *client, - struct wl_resource *source) +source_destroy(struct wl_client *client, struct wl_resource *source) { wl_resource_destroy(source); } static struct wl_data_source_interface data_source_implementation = { - .offer = &source_offer, - .destroy = &source_destroy + .offer = source_offer, + .destroy = source_destroy, }; static void @@ -113,13 +105,13 @@ data_destroy(struct wl_resource *source) wl_array_release(&data->mime_types); /* After this data_source is destroyed, each of the data_offer objects - * associated with the data_source has a pointer to a free'd struct. We - * can't destroy the resources because this results in a segfault on the - * client when it correctly tries to call data_source.destroy. However, a - * misbehaving client could still attempt to call accept or receive on the - * data_offer, which would crash the server. - * - * So, we clear the user data on each of the offers to protect us. */ + * associated with the data_source has a pointer to a free'd struct. We can't + * destroy the resources because this results in a segfault on the client when + * it correctly tries to call data_source.destroy. However, a misbehaving + * client could still attempt to call accept or receive on the data_offer, + * which would crash the server. + * + * So, we clear the user data on each of the offers to protect us. */ wl_resource_for_each (offer, &data->offers) { wl_resource_set_user_data(offer, NULL); wl_resource_set_destructor(offer, NULL); @@ -145,8 +137,7 @@ data_new(void) } struct wl_resource * -data_source_new(struct wl_client *client, - uint32_t version, uint32_t id) +data_source_new(struct wl_client *client, uint32_t version, uint32_t id) { struct data *data; @@ -156,35 +147,29 @@ data_source_new(struct wl_client *client, return NULL; /* Add the data source to the client. */ - data->source = wl_resource_create(client, &wl_data_source_interface, - version, id); + data->source = wl_resource_create(client, &wl_data_source_interface, version, id); /* Destroy the data object when the source disappears. */ - wl_resource_set_implementation(data->source, &data_source_implementation, - data, &data_destroy); + wl_resource_set_implementation(data->source, &data_source_implementation, data, &data_destroy); return data->source; } struct wl_resource * -data_offer_new(struct wl_client *client, - struct wl_resource *source, - uint32_t version) +data_offer_new(struct wl_client *client, struct wl_resource *source, uint32_t version) { struct data *data = wl_resource_get_user_data(source); struct wl_resource *offer; offer = wl_resource_create(client, &wl_data_offer_interface, version, 0); - wl_resource_set_implementation(offer, &data_offer_implementation, - data, &remove_resource); + wl_resource_set_implementation(offer, &data_offer_implementation, data, &remove_resource); wl_list_insert(&data->offers, wl_resource_get_link(offer)); return offer; } void -data_send_mime_types(struct wl_resource *source, - struct wl_resource *offer) +data_send_mime_types(struct wl_resource *source, struct wl_resource *offer) { struct data *data = wl_resource_get_user_data(source); char **mime_type; diff --git a/libswc/data.h b/libswc/data.h @@ -28,14 +28,8 @@ struct wl_client; -struct wl_resource *data_source_new(struct wl_client *client, - uint32_t version, uint32_t id); - -struct wl_resource *data_offer_new(struct wl_client *client, - struct wl_resource *source, - uint32_t version); - -void data_send_mime_types(struct wl_resource *source, - struct wl_resource *offer); +struct wl_resource *data_source_new(struct wl_client *client, uint32_t version, uint32_t id); +struct wl_resource *data_offer_new(struct wl_client *client, struct wl_resource *source, uint32_t version); +void data_send_mime_types(struct wl_resource *source, struct wl_resource *offer); #endif diff --git a/libswc/data_device.c b/libswc/data_device.c @@ -27,17 +27,14 @@ static void start_drag(struct wl_client *client, struct wl_resource *resource, - struct wl_resource *source_resource, - struct wl_resource *origin_resource, + struct wl_resource *source_resource, struct wl_resource *origin_resource, struct wl_resource *icon_resource, uint32_t serial) { /* XXX: Implement */ } static void -set_selection(struct wl_client *client, - struct wl_resource *resource, - struct wl_resource *data_source, uint32_t serial) +set_selection(struct wl_client *client, struct wl_resource *resource, struct wl_resource *data_source, uint32_t serial) { struct data_device *data_device = wl_resource_get_user_data(resource); @@ -52,17 +49,15 @@ set_selection(struct wl_client *client, data_device->selection = data_source; - if (data_source) { + if (data_source) wl_resource_add_destroy_listener(data_source, &data_device->selection_destroy_listener); - } - send_event(&data_device->event_signal, - DATA_DEVICE_EVENT_SELECTION_CHANGED, NULL); + send_event(&data_device->event_signal, DATA_DEVICE_EVENT_SELECTION_CHANGED, NULL); } static struct wl_data_device_interface data_device_implementation = { - .start_drag = &start_drag, - .set_selection = &set_selection + .start_drag = start_drag, + .set_selection = set_selection, }; static void @@ -71,8 +66,7 @@ handle_selection_destroy(struct wl_listener *listener, void *data) struct data_device *data_device = wl_container_of(listener, data_device, selection_destroy_listener); data_device->selection = NULL; - send_event(&data_device->event_signal, - DATA_DEVICE_EVENT_SELECTION_CHANGED, NULL); + send_event(&data_device->event_signal, DATA_DEVICE_EVENT_SELECTION_CHANGED, NULL); } bool @@ -95,22 +89,17 @@ data_device_finalize(struct data_device *data_device) } void -data_device_bind(struct data_device *data_device, - struct wl_client *client, uint32_t version, uint32_t id) +data_device_bind(struct data_device *data_device, struct wl_client *client, uint32_t version, uint32_t id) { struct wl_resource *resource; - resource = wl_resource_create(client, &wl_data_device_interface, - version, id); - wl_resource_set_implementation(resource, &data_device_implementation, - data_device, &remove_resource); + resource = wl_resource_create(client, &wl_data_device_interface, version, id); + wl_resource_set_implementation(resource, &data_device_implementation, data_device, &remove_resource); wl_list_insert(&data_device->resources, &resource->link); } static struct wl_resource * -new_offer(struct wl_resource *resource, - struct wl_client *client, - struct wl_resource *source) +new_offer(struct wl_resource *resource, struct wl_client *client, struct wl_resource *source) { struct wl_resource *offer; @@ -122,8 +111,7 @@ new_offer(struct wl_resource *resource, } void -data_device_offer_selection(struct data_device *data_device, - struct wl_client *client) +data_device_offer_selection(struct data_device *data_device, struct wl_client *client) { struct wl_resource *resource; struct wl_resource *offer; @@ -136,9 +124,7 @@ data_device_offer_selection(struct data_device *data_device, return; /* If we don't have a selection, send NULL to the client. */ - offer = data_device->selection - ? new_offer(resource, client, data_device->selection) - : NULL; + offer = data_device->selection ? new_offer(resource, client, data_device->selection) : NULL; wl_data_device_send_selection(resource, offer); } diff --git a/libswc/data_device.h b/libswc/data_device.h @@ -44,11 +44,7 @@ struct data_device { bool data_device_initialize(struct data_device *data_device); void data_device_finalize(struct data_device *data_device); - -void data_device_bind(struct data_device *data_device, - struct wl_client *client, uint32_t version, uint32_t id); - -void data_device_offer_selection(struct data_device *data_device, - struct wl_client *client); +void data_device_bind(struct data_device *data_device, struct wl_client *client, uint32_t version, uint32_t id); +void data_device_offer_selection(struct data_device *data_device, struct wl_client *client); #endif diff --git a/libswc/data_device_manager.c b/libswc/data_device_manager.c @@ -27,50 +27,41 @@ #include "internal.h" #include "seat.h" -static struct - { +static struct { struct wl_global *global; } data_device_manager; static void -create_data_source(struct wl_client *client, - struct wl_resource *resource, uint32_t id) +create_data_source(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct wl_resource *data_source; - data_source = data_source_new(client, - wl_resource_get_version(resource), id); + data_source = data_source_new(client, wl_resource_get_version(resource), id); if (!data_source) wl_resource_post_no_memory(resource); } static void -get_data_device(struct wl_client *client, - struct wl_resource *resource, uint32_t id, - struct wl_resource *seat_resource) +get_data_device(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *seat_resource) { - data_device_bind(swc.seat->data_device, client, - wl_resource_get_version(resource), id); + data_device_bind(swc.seat->data_device, client, wl_resource_get_version(resource), id); } -static struct wl_data_device_manager_interface - data_device_manager_implementation = { - .create_data_source = &create_data_source, - .get_data_device = &get_data_device - }; +static struct wl_data_device_manager_interface data_device_manager_implementation = { + .create_data_source = create_data_source, + .get_data_device = get_data_device, +}; static void -bind_data_device_manager(struct wl_client *client, void *data, - uint32_t version, uint32_t id) +bind_data_device_manager(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wl_resource *resource; if (version > 1) version = 1; - resource = wl_resource_create(client, &wl_data_device_manager_interface, - version, id); + resource = wl_resource_create(client, &wl_data_device_manager_interface, version, id); wl_resource_set_implementation(resource, &data_device_manager_implementation, NULL, NULL); } diff --git a/libswc/drm.c b/libswc/drm.c @@ -46,8 +46,7 @@ struct swc_drm swc_drm; -static struct - { +static struct { char path[128]; uint32_t taken_ids; @@ -57,51 +56,40 @@ static struct } drm; static void -authenticate(struct wl_client *client, - struct wl_resource *resource, uint32_t magic) +authenticate(struct wl_client *client, struct wl_resource *resource, uint32_t magic) { wl_drm_send_authenticated(resource); } static void -create_buffer(struct wl_client *client, - struct wl_resource *resource, uint32_t id, - uint32_t name, int32_t width, int32_t height, - uint32_t stride, uint32_t format) +create_buffer(struct wl_client *client, struct wl_resource *resource, uint32_t id, + uint32_t name, int32_t width, int32_t height, uint32_t stride, uint32_t format) { - wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_NAME, - "GEM names are not supported, " - "use a PRIME fd instead"); + wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_NAME, "GEM names are not supported, use a PRIME fd instead"); } static void -create_planar_buffer(struct wl_client *client, - struct wl_resource *resource, uint32_t id, - uint32_t name, int32_t width, int32_t height, - uint32_t format, +create_planar_buffer(struct wl_client *client, struct wl_resource *resource, uint32_t id, + uint32_t name, int32_t width, int32_t height, uint32_t format, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2) { - wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT, - "planar buffers are not supported\n"); + wl_resource_post_error(resource, WL_DRM_ERROR_INVALID_FORMAT, "planar buffers are not supported\n"); } static void -create_prime_buffer(struct wl_client *client, - struct wl_resource *resource, uint32_t id, - int32_t fd, int32_t width, int32_t height, - uint32_t format, +create_prime_buffer(struct wl_client *client, struct wl_resource *resource, uint32_t id, + int32_t fd, int32_t width, int32_t height, uint32_t format, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2) { struct wld_buffer *buffer; struct wl_resource *buffer_resource; - union wld_object object = {.i = fd }; + union wld_object object = { .i = fd }; - buffer = wld_import_buffer(swc.drm->context, WLD_DRM_OBJECT_PRIME_FD, - object, width, height, format, stride0); + buffer = wld_import_buffer(swc.drm->context, WLD_DRM_OBJECT_PRIME_FD, object, width, height, format, stride0); close(fd); if (!buffer) @@ -121,17 +109,16 @@ error0: } static const struct wl_drm_interface drm_implementation = { - .authenticate = &authenticate, - .create_buffer = &create_buffer, - .create_planar_buffer = &create_planar_buffer, - .create_prime_buffer = &create_prime_buffer + .authenticate = authenticate, + .create_buffer = create_buffer, + .create_planar_buffer = create_planar_buffer, + .create_prime_buffer = create_prime_buffer, }; static int select_card(const struct dirent *entry) { unsigned num; - return sscanf(entry->d_name, "card%u", &num) == 1; } @@ -150,8 +137,7 @@ find_primary_drm_device(char *path, size_t size) return false; for (index = 0; index < num_cards; ++index) { - snprintf(path, size, "/sys/class/drm/%s/device/boot_vga", - cards[index]->d_name); + snprintf(path, size, "/sys/class/drm/%s/device/boot_vga", cards[index]->d_name); if ((file = fopen(path, "r"))) { ret = fscanf(file, "%hhu", &boot_vga); @@ -184,26 +170,20 @@ find_primary_drm_device(char *path, size_t size) } static bool -find_available_crtc(drmModeRes *resources, - drmModeConnector *connector, - uint32_t taken_crtcs, uint32_t *crtc) +find_available_crtc(drmModeRes *resources, drmModeConnector *connector, uint32_t taken_crtcs, int *crtc_index) { - uint32_t encoder_index, crtc_index; + int i, j; uint32_t possible_crtcs; drmModeEncoder *encoder; - for (encoder_index = 0; - encoder_index < connector->count_encoders; - ++encoder_index) { - encoder = drmModeGetEncoder(swc.drm->fd, - connector->encoders[encoder_index]); + for (i = 0; i < connector->count_encoders; ++i) { + encoder = drmModeGetEncoder(swc.drm->fd, connector->encoders[i]); possible_crtcs = encoder->possible_crtcs; drmModeFreeEncoder(encoder); - for (crtc_index = 0; crtc_index < resources->count_crtcs; ++crtc_index) { - if ((possible_crtcs & (1 << crtc_index)) - && !(taken_crtcs & (1 << crtc_index))) { - *crtc = crtc_index; + for (j = 0; j < resources->count_crtcs; ++j) { + if ((possible_crtcs & (1 << j)) && !(taken_crtcs & (1 << j))) { + *crtc_index = j; return true; } } @@ -225,14 +205,12 @@ find_available_id(uint32_t *id) } static void -handle_vblank(int fd, unsigned int sequence, unsigned int sec, - unsigned int usec, void *data) +handle_vblank(int fd, unsigned int sequence, unsigned int sec, unsigned int usec, void *data) { } static void -handle_page_flip(int fd, unsigned int sequence, unsigned int sec, - unsigned int usec, void *data) +handle_page_flip(int fd, unsigned int sequence, unsigned int sec, unsigned int usec, void *data) { struct drm_handler *handler = data; @@ -241,21 +219,19 @@ handle_page_flip(int fd, unsigned int sequence, unsigned int sec, static drmEventContext event_context = { .version = DRM_EVENT_CONTEXT_VERSION, - .vblank_handler = &handle_vblank, - .page_flip_handler = &handle_page_flip + .vblank_handler = handle_vblank, + .page_flip_handler = handle_page_flip, }; static int handle_data(int fd, uint32_t mask, void *data) { drmHandleEvent(fd, &event_context); - return 1; } static void -bind_drm(struct wl_client *client, void *data, uint32_t version, - uint32_t id) +bind_drm(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wl_resource *resource; @@ -296,20 +272,17 @@ drm_initialize(void) goto error1; } - if (snprintf(drm.path, sizeof drm.path, "/dev/dri/renderD%d", - minor(master.st_rdev) + 0x80) >= sizeof drm.path) { + if (snprintf(drm.path, sizeof drm.path, "/dev/dri/renderD%d", minor(master.st_rdev) + 0x80) >= sizeof drm.path) { ERROR("Render node path is too long"); goto error1; } if (stat(drm.path, &render) != 0) { - ERROR("Could not stat render node for primary DRM device: %s\n", - strerror(errno)); + ERROR("Could not stat render node for primary DRM device: %s\n", strerror(errno)); goto error1; } - if (master.st_mode != render.st_mode - || minor(master.st_rdev) + 0x80 != minor(render.st_rdev)) { + if (master.st_mode != render.st_mode || minor(master.st_rdev) + 0x80 != minor(render.st_rdev)) { ERROR("Render node does not have expected mode or minor number\n"); goto error1; } @@ -332,8 +305,7 @@ drm_initialize(void) } if (!wld_drm_is_dumb(swc.drm->context)) { - drm.global = wl_global_create(swc.display, &wl_drm_interface, 2, - NULL, &bind_drm); + drm.global = wl_global_create(swc.display, &wl_drm_interface, 2, NULL, &bind_drm); if (!drm.global) { ERROR("Could not create wl_drm global\n"); @@ -371,7 +343,7 @@ drm_create_screens(struct wl_list *screens) { drmModeRes *resources; drmModeConnector *connector; - uint32_t index; + int i; struct output *output; uint32_t taken_crtcs = 0; @@ -380,18 +352,15 @@ drm_create_screens(struct wl_list *screens) return false; } - for (index = 0; index < resources->count_connectors; - ++index, drmModeFreeConnector(connector)) { - connector = drmModeGetConnector(swc.drm->fd, - resources->connectors[index]); + for (i = 0; i < resources->count_connectors; ++i, drmModeFreeConnector(connector)) { + connector = drmModeGetConnector(swc.drm->fd, resources->connectors[i]); if (connector->connection == DRM_MODE_CONNECTED) { - uint32_t crtc_index; + int crtc_index; uint32_t id; - if (!find_available_crtc(resources, connector, taken_crtcs, - &crtc_index)) { - WARNING("Could not find CRTC for connector %u\n", index); + if (!find_available_crtc(resources, connector, taken_crtcs, &crtc_index)) { + WARNING("Could not find CRTC for connector %d\n", i); continue; } diff --git a/libswc/evdev_device.c b/libswc/evdev_device.c @@ -50,47 +50,42 @@ timeval_to_msec(struct timeval *time) } static void -handle_key_event(struct evdev_device *device, - struct input_event *input_event) +handle_key_event(struct evdev_device *device, struct input_event *ev) { - uint32_t time = timeval_to_msec(&input_event->time); + uint32_t time = timeval_to_msec(&ev->time); uint32_t state; - if ((input_event->code >= BTN_MISC && input_event->code <= BTN_GEAR_UP) - || input_event->code >= BTN_TRIGGER_HAPPY) { - state = input_event->value ? WL_POINTER_BUTTON_STATE_PRESSED - : WL_POINTER_BUTTON_STATE_RELEASED; - device->handler->button(time, input_event->code, state); + if ((ev->code >= BTN_MISC && ev->code <= BTN_GEAR_UP) || ev->code >= BTN_TRIGGER_HAPPY) { + state = ev->value ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED; + device->handler->button(time, ev->code, state); } else { - state = input_event->value ? WL_KEYBOARD_KEY_STATE_PRESSED - : WL_KEYBOARD_KEY_STATE_RELEASED; - device->handler->key(time, input_event->code, state); + state = ev->value ? WL_KEYBOARD_KEY_STATE_PRESSED : WL_KEYBOARD_KEY_STATE_RELEASED; + device->handler->key(time, ev->code, state); } } static void -handle_rel_event(struct evdev_device *device, - struct input_event *input_event) +handle_rel_event(struct evdev_device *device, struct input_event *ev) { - uint32_t time = timeval_to_msec(&input_event->time); + uint32_t time = timeval_to_msec(&ev->time); uint32_t axis, amount; - switch (input_event->code) { + switch (ev->code) { case REL_X: - device->motion.rel.dx += input_event->value; + device->motion.rel.dx += ev->value; device->motion.rel.pending = true; return; case REL_Y: - device->motion.rel.dy += input_event->value; + device->motion.rel.dy += ev->value; device->motion.rel.pending = true; return; case REL_WHEEL: axis = WL_POINTER_AXIS_VERTICAL_SCROLL; - amount = -AXIS_STEP_DISTANCE * wl_fixed_from_int(input_event->value); + amount = -AXIS_STEP_DISTANCE * wl_fixed_from_int(ev->value); break; case REL_HWHEEL: axis = WL_POINTER_AXIS_HORIZONTAL_SCROLL; - amount = AXIS_STEP_DISTANCE * wl_fixed_from_int(input_event->value); + amount = AXIS_STEP_DISTANCE * wl_fixed_from_int(ev->value); break; default: return; @@ -100,28 +95,25 @@ handle_rel_event(struct evdev_device *device, } static void -handle_abs_event(struct evdev_device *device, - struct input_event *input_event) +handle_abs_event(struct evdev_device *device, struct input_event *input_event) { } -static void (*event_handlers[])(struct evdev_device *device, - struct input_event *input_event) = { - [EV_KEY] = &handle_key_event, - [EV_REL] = &handle_rel_event, - [EV_ABS] = &handle_abs_event +static void (*event_handlers[])(struct evdev_device *device, struct input_event *ev) = { + [EV_KEY] = handle_key_event, + [EV_REL] = handle_rel_event, + [EV_ABS] = handle_abs_event, }; static bool -is_motion_event(struct input_event *event) +is_motion_event(struct input_event *ev) { - return (event->type == EV_REL && (event->code == REL_X || event->code == REL_Y)) - || (event->type == EV_ABS && (event->code == ABS_X || event->code == ABS_Y)); + return (ev->type == EV_REL && (ev->code == REL_X || ev->code == REL_Y)) + || (ev->type == EV_ABS && (ev->code == ABS_X || ev->code == ABS_Y)); } static void -handle_motion_events(struct evdev_device *device, - uint32_t time) +handle_motion_events(struct evdev_device *device, uint32_t time) { if (device->motion.rel.pending) { wl_fixed_t dx = wl_fixed_from_int(device->motion.rel.dx); @@ -136,16 +128,13 @@ handle_motion_events(struct evdev_device *device, } static void -handle_event(struct evdev_device *device, - struct input_event *event) +handle_event(struct evdev_device *device, struct input_event *ev) { - if (!is_motion_event(event)) - handle_motion_events(device, timeval_to_msec(&event->time)); + if (!is_motion_event(ev)) + handle_motion_events(device, timeval_to_msec(&ev->time)); - if (event->type < ARRAY_SIZE(event_handlers) - && event_handlers[event->type]) { - event_handlers[event->type](device, event); - } + if (ev->type < ARRAY_SIZE(event_handlers) && event_handlers[ev->type]) + event_handlers[ev->type](device, ev); } static void @@ -162,29 +151,30 @@ handle_data(int fd, uint32_t mask, void *data) { struct evdev_device *device = data; struct input_event event; - unsigned flags = device->needs_sync ? LIBEVDEV_READ_FLAG_FORCE_SYNC - : LIBEVDEV_READ_FLAG_NORMAL; + unsigned flags = device->needs_sync ? LIBEVDEV_READ_FLAG_FORCE_SYNC : LIBEVDEV_READ_FLAG_NORMAL; int ret; device->needs_sync = false; - while (true) { + for (;;) { ret = libevdev_next_event(device->dev, flags, &event); - if (ret < 0) - goto done; - else if (ret == LIBEVDEV_READ_STATUS_SUCCESS) + switch (ret) { + case LIBEVDEV_READ_STATUS_SUCCESS: handle_event(device, &event); - else { + break; + case LIBEVDEV_READ_STATUS_SYNC: while (ret == LIBEVDEV_READ_STATUS_SYNC) { - ret = libevdev_next_event(device->dev, LIBEVDEV_READ_FLAG_SYNC, - &event); + ret = libevdev_next_event(device->dev, LIBEVDEV_READ_FLAG_SYNC, &event); if (ret < 0) goto done; handle_event(device, &event); } + break; + default: + goto done; } } @@ -240,8 +230,9 @@ evdev_device_new(const char *path, const struct evdev_device_handler *handler) } if (libevdev_has_event_code(device->dev, EV_REL, REL_X) - && libevdev_has_event_code(device->dev, EV_REL, REL_Y) - && libevdev_has_event_code(device->dev, EV_KEY, BTN_MOUSE)) { + && libevdev_has_event_code(device->dev, EV_REL, REL_Y) + && libevdev_has_event_code(device->dev, EV_KEY, BTN_MOUSE)) + { device->capabilities |= WL_SEAT_CAPABILITY_POINTER; DEBUG("\tThis device is a pointer\n"); } @@ -279,12 +270,10 @@ evdev_device_reopen(struct evdev_device *device) if (device->source) close_device(device); - device->fd = launch_open_device(device->path, - O_RDWR | O_NONBLOCK | O_CLOEXEC); + device->fd = launch_open_device(device->path, O_RDWR | O_NONBLOCK | O_CLOEXEC); if (device->fd == -1) { - WARNING("Failed to reopen input device at %s: %s\n", - device->path, strerror(errno)); + WARNING("Failed to reopen input device at %s: %s\n", device->path, strerror(errno)); goto error0; } @@ -293,8 +282,8 @@ evdev_device_reopen(struct evdev_device *device) goto error1; } - /* According to libevdev documentation, after changing the fd for the - * device, you should force a sync to bring it's state up to date. */ + /* According to libevdev documentation, after changing the fd for the device, + * you should force a sync to bring it's state up to date. */ device->needs_sync = true; device->source = wl_event_loop_add_fd(swc.event_loop, device->fd, WL_EVENT_READABLE, handle_data, device); diff --git a/libswc/evdev_device.h b/libswc/evdev_device.h @@ -50,12 +50,9 @@ struct evdev_device { const struct evdev_device_handler *handler; - struct - { - struct - { - struct - { + struct { + struct { + struct { struct input_absinfo x, y; } info; @@ -63,8 +60,7 @@ struct evdev_device { bool pending; } abs; - struct - { + struct { int32_t dx, dy; bool pending; } rel; @@ -77,9 +73,7 @@ struct evdev_device { }; struct evdev_device *evdev_device_new(const char *path, const struct evdev_device_handler *handler); - void evdev_device_destroy(struct evdev_device *device); - bool evdev_device_reopen(struct evdev_device *device); #endif diff --git a/libswc/event.h b/libswc/event.h @@ -12,28 +12,26 @@ */ struct event { /** - * The type of event that was sent. - * - * The meaning of this field depends on the type of object containing the - * event_signal that passed this event. - */ + * The type of event that was sent. + * + * The meaning of this field depends on the type of object containing the + * event_signal that passed this event. + */ uint32_t type; /** - * Data specific to the event type. - * - * Unless explicitly stated in the description of the event type, this - * value is undefined. - */ + * Data specific to the event type. + * + * Unless explicitly stated in the description of the event type, this value + * is undefined. + */ void *data; }; static inline void -send_event(struct wl_signal *signal, uint32_t type, - void *event_data) +send_event(struct wl_signal *signal, uint32_t type, void *event_data) { - struct event event = {.type = type, .data = event_data }; - + struct event event = { .type = type, .data = event_data }; wl_signal_emit(signal, &event); } diff --git a/libswc/framebuffer_plane.c b/libswc/framebuffer_plane.c @@ -45,9 +45,7 @@ struct framebuffer { }; static bool -framebuffer_export(struct wld_exporter *exporter, - struct wld_buffer *buffer, - uint32_t type, union wld_object *object) +framebuffer_export(struct wld_exporter *exporter, struct wld_buffer *buffer, uint32_t type, union wld_object *object) { struct framebuffer *framebuffer = wl_container_of(exporter, framebuffer, exporter); @@ -103,8 +101,7 @@ attach(struct view *view, struct wld_buffer *buffer) if (!(framebuffer = malloc(sizeof *framebuffer))) return -ENOMEM; - ret = drmModeAddFB(swc.drm->fd, buffer->width, buffer->height, 24, 32, - buffer->pitch, object.u32, &framebuffer->id); + ret = drmModeAddFB(swc.drm->fd, buffer->width, buffer->height, 24, 32, buffer->pitch, object.u32, &framebuffer->id); if (ret < 0) { free(framebuffer); @@ -120,21 +117,17 @@ attach(struct view *view, struct wld_buffer *buffer) } if (plane->need_modeset) { - ret = drmModeSetCrtc(swc.drm->fd, plane->crtc, object.u32, 0, 0, - plane->connectors.data, plane->connectors.size / 4, - &plane->mode.info); + ret = drmModeSetCrtc(swc.drm->fd, plane->crtc, object.u32, 0, 0, plane->connectors.data, plane->connectors.size / 4, &plane->mode.info); if (ret == 0) { wl_event_loop_add_idle(swc.event_loop, &send_frame, plane); plane->need_modeset = false; } else { - ERROR("Could not set CRTC to next framebuffer: %s\n", - strerror(-ret)); + ERROR("Could not set CRTC to next framebuffer: %s\n", strerror(-ret)); return ret; } } else { - ret = drmModePageFlip(swc.drm->fd, plane->crtc, object.u32, - DRM_MODE_PAGE_FLIP_EVENT, &plane->drm_handler); + ret = drmModePageFlip(swc.drm->fd, plane->crtc, object.u32, DRM_MODE_PAGE_FLIP_EVENT, &plane->drm_handler); if (ret < 0) { ERROR("Page flip failed: %s\n", strerror(errno)); @@ -149,21 +142,19 @@ static bool move(struct view *view, int32_t x, int32_t y) { view_set_position(view, x, y); - return true; } const static struct view_impl view_impl = { - .update = &update, - .attach = &attach, - .move = &move + .update = update, + .attach = attach, + .move = move, }; static void handle_page_flip(struct drm_handler *handler, uint32_t time) { struct framebuffer_plane *plane = wl_container_of(handler, plane, drm_handler); - view_frame(&plane->view, time); } @@ -181,22 +172,17 @@ handle_swc_event(struct wl_listener *listener, void *data) } bool -framebuffer_plane_initialize(struct framebuffer_plane *plane, - uint32_t crtc, struct mode *mode, - uint32_t *connectors, - uint32_t num_connectors) +framebuffer_plane_initialize(struct framebuffer_plane *plane, uint32_t crtc, struct mode *mode, uint32_t *connectors, uint32_t num_connectors) { uint32_t *plane_connectors; if (!(plane->original_crtc_state = drmModeGetCrtc(swc.drm->fd, crtc))) { - ERROR("Failed to get CRTC state for CRTC %u: %s\n", - crtc, strerror(errno)); + ERROR("Failed to get CRTC state for CRTC %u: %s\n", crtc, strerror(errno)); goto error0; } wl_array_init(&plane->connectors); - plane_connectors = wl_array_add(&plane->connectors, - num_connectors * sizeof connectors[0]); + plane_connectors = wl_array_add(&plane->connectors, num_connectors * sizeof connectors[0]); if (!plane_connectors) { ERROR("Failed to allocate connector array\n"); @@ -227,7 +213,6 @@ framebuffer_plane_finalize(struct framebuffer_plane *plane) { wl_array_release(&plane->connectors); drmModeCrtcPtr crtc = plane->original_crtc_state; - drmModeSetCrtc(swc.drm->fd, crtc->crtc_id, crtc->buffer_id, - crtc->x, crtc->y, NULL, 0, &crtc->mode); + drmModeSetCrtc(swc.drm->fd, crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y, NULL, 0, &crtc->mode); drmModeFreeCrtc(crtc); } diff --git a/libswc/framebuffer_plane.h b/libswc/framebuffer_plane.h @@ -40,11 +40,7 @@ struct framebuffer_plane { struct wl_listener swc_listener; }; -bool framebuffer_plane_initialize(struct framebuffer_plane *plane, - uint32_t crtc, struct mode *mode, - uint32_t *connectors, - uint32_t num_connectors); - +bool framebuffer_plane_initialize(struct framebuffer_plane *plane, uint32_t crtc, struct mode *mode, uint32_t *connectors, uint32_t num_connectors); void framebuffer_plane_finalize(struct framebuffer_plane *plane); #endif diff --git a/libswc/input.c b/libswc/input.c @@ -28,8 +28,7 @@ #include "util.h" static inline void -focus(struct input_focus *input_focus, - struct compositor_view *view) +focus(struct input_focus *input_focus, struct compositor_view *view) { struct wl_resource *resource = NULL; @@ -39,8 +38,7 @@ focus(struct input_focus *input_focus, client = wl_resource_get_client(view->surface->resource); resource = wl_resource_find_for_client(&input_focus->resources, client); - wl_signal_add(&view->destroy_signal, - &input_focus->view_destroy_listener); + wl_signal_add(&view->destroy_signal, &input_focus->view_destroy_listener); if (resource) input_focus->handler->enter(input_focus->handler, resource, view); @@ -56,15 +54,12 @@ unfocus(struct input_focus *input_focus) if (input_focus->view) wl_list_remove(&input_focus->view_destroy_listener.link); - if (input_focus->resource) { - input_focus->handler->leave(input_focus->handler, input_focus->resource, - input_focus->view); - } + if (input_focus->resource) + input_focus->handler->leave(input_focus->handler, input_focus->resource, input_focus->view); } static void -handle_focus_view_destroy(struct wl_listener *listener, - void *data) +handle_focus_view_destroy(struct wl_listener *listener, void *data) { struct input_focus *input_focus = wl_container_of(listener, input_focus, view_destroy_listener); @@ -73,8 +68,7 @@ handle_focus_view_destroy(struct wl_listener *listener, } bool -input_focus_initialize(struct input_focus *input_focus, - struct input_focus_handler *handler) +input_focus_initialize(struct input_focus *input_focus, struct input_focus_handler *handler) { input_focus->resource = NULL; input_focus->view = NULL; @@ -94,11 +88,9 @@ input_focus_finalize(struct input_focus *input_focus) } void -input_focus_add_resource(struct input_focus *input_focus, - struct wl_resource *resource) +input_focus_add_resource(struct input_focus *input_focus, struct wl_resource *resource) { - /* If this new input resource corresponds to our focus, set it as our - * focus. */ + /* If this new input resource corresponds to our focus, set it as our focus. */ if (input_focus->view) { struct wl_client *client, *surface_client; @@ -106,8 +98,7 @@ input_focus_add_resource(struct input_focus *input_focus, surface_client = wl_resource_get_client(input_focus->view->surface->resource); if (client == surface_client) { - input_focus->handler->enter(input_focus->handler, resource, - input_focus->view); + input_focus->handler->enter(input_focus->handler, resource, input_focus->view); input_focus->resource = resource; } } @@ -116,8 +107,7 @@ input_focus_add_resource(struct input_focus *input_focus, } void -input_focus_remove_resource(struct input_focus *input_focus, - struct wl_resource *resource) +input_focus_remove_resource(struct input_focus *input_focus, struct wl_resource *resource) { if (resource == input_focus->resource) input_focus->resource = NULL; @@ -126,8 +116,7 @@ input_focus_remove_resource(struct input_focus *input_focus, } void -input_focus_set(struct input_focus *input_focus, - struct compositor_view *view) +input_focus_set(struct input_focus *input_focus, struct compositor_view *view) { struct input_focus_event_data data; @@ -144,6 +133,4 @@ input_focus_set(struct input_focus *input_focus, focus(input_focus, view); send_event(&input_focus->event_signal, INPUT_FOCUS_EVENT_CHANGED, &data); - - return; } diff --git a/libswc/input.h b/libswc/input.h @@ -38,12 +38,8 @@ struct input_focus_event_data { }; struct input_focus_handler { - void (*enter)(struct input_focus_handler *handler, - struct wl_resource *resource, - struct compositor_view *view); - void (*leave)(struct input_focus_handler *handler, - struct wl_resource *resource, - struct compositor_view *view); + void (*enter)(struct input_focus_handler *handler, struct wl_resource *resource, struct compositor_view *view); + void (*leave)(struct input_focus_handler *handler, struct wl_resource *resource, struct compositor_view *view); }; struct input_focus { @@ -57,19 +53,11 @@ struct input_focus { struct wl_signal event_signal; }; -bool input_focus_initialize(struct input_focus *input_focus, - struct input_focus_handler *input_handler); - +bool input_focus_initialize(struct input_focus *input_focus, struct input_focus_handler *input_handler); void input_focus_finalize(struct input_focus *input_focus); - -void input_focus_add_resource(struct input_focus *input_focus, - struct wl_resource *resource); - -void input_focus_remove_resource(struct input_focus *input_focus, - struct wl_resource *resource); - -void input_focus_set(struct input_focus *input_focus, - struct compositor_view *view); +void input_focus_add_resource(struct input_focus *input_focus, struct wl_resource *resource); +void input_focus_remove_resource(struct input_focus *input_focus, struct wl_resource *resource); +void input_focus_set(struct input_focus *input_focus, struct compositor_view *view); /* }}} */ diff --git a/libswc/keyboard.c b/libswc/keyboard.c @@ -39,23 +39,19 @@ static const int repeat_delay = 500, repeat_rate = 40; static void -enter(struct input_focus_handler *handler, - struct wl_resource *resource, struct compositor_view *view) +enter(struct input_focus_handler *handler, struct wl_resource *resource, struct compositor_view *view) { struct keyboard *keyboard = wl_container_of(handler, keyboard, focus_handler); struct keyboard_modifier_state *state = &keyboard->modifier_state; uint32_t serial; serial = wl_display_next_serial(swc.display); - wl_keyboard_send_modifiers(resource, serial, state->depressed, - state->locked, state->latched, state->group); - wl_keyboard_send_enter(resource, serial, view->surface->resource, - &keyboard->client_keys); + wl_keyboard_send_modifiers(resource, serial, state->depressed, state->locked, state->latched, state->group); + wl_keyboard_send_enter(resource, serial, view->surface->resource, &keyboard->client_keys); } static void -leave(struct input_focus_handler *handler, - struct wl_resource *resource, struct compositor_view *view) +leave(struct input_focus_handler *handler, struct wl_resource *resource, struct compositor_view *view) { uint32_t serial; @@ -64,8 +60,7 @@ leave(struct input_focus_handler *handler, } static bool -client_handle_key(struct keyboard *keyboard, uint32_t time, - struct key *key, uint32_t state) +client_handle_key(struct keyboard *keyboard, uint32_t time, struct key *key, uint32_t state) { uint32_t *value; @@ -83,10 +78,8 @@ client_handle_key(struct keyboard *keyboard, uint32_t time, } } - if (keyboard->focus.resource) { - wl_keyboard_send_key(keyboard->focus.resource, key->press.serial, time, - key->press.value, state); - } + if (keyboard->focus.resource) + wl_keyboard_send_key(keyboard->focus.resource, key->press.serial, time, key->press.value, state); return true; } @@ -104,9 +97,7 @@ client_handle_modifiers(struct keyboard *keyboard, const struct keyboard_modifie client = wl_resource_get_client(keyboard->focus.resource); display = wl_client_get_display(client); serial = wl_display_next_serial(display); - wl_keyboard_send_modifiers(keyboard->focus.resource, serial, - state->depressed, state->locked, state->latched, - state->group); + wl_keyboard_send_modifiers(keyboard->focus.resource, serial, state->depressed, state->locked, state->latched, state->group); return true; } @@ -160,16 +151,15 @@ keyboard_reset(struct keyboard *keyboard) wl_array_for_each (key, &keyboard->keys) { if (key->handler) { key->press.serial = wl_display_next_serial(swc.display); - key->handler->key(keyboard, time, key, - WL_KEYBOARD_KEY_STATE_RELEASED); - /* Don't bother updating the XKB state because we will be resetting - * it later on and it is unlikely that a key handler cares about the - * keyboard state for release events. */ + key->handler->key(keyboard, time, key, WL_KEYBOARD_KEY_STATE_RELEASED); + /* Don't bother updating the XKB state because we will be resetting it + * later on and it is unlikely that a key handler cares about the keyboard + * state for release events. */ } } /* We should have removed all the client keys by calling the client key - * handler. */ + * handler. */ assert(keyboard->client_keys.size == 0); keyboard->keys.size = 0; keyboard->modifier_state = (struct keyboard_modifier_state){}; @@ -181,8 +171,7 @@ keyboard_reset(struct keyboard *keyboard) * Sets the focus of the keyboard to the specified surface. */ void -keyboard_set_focus(struct keyboard *keyboard, - struct compositor_view *view) +keyboard_set_focus(struct keyboard *keyboard, struct compositor_view *view) { input_focus_set(&keyboard->focus, view); } @@ -194,46 +183,36 @@ release(struct wl_client *client, struct wl_resource *resource) } static struct wl_keyboard_interface keyboard_implementation = { - .release = &release, + .release = release, }; static void unbind(struct wl_resource *resource) { struct keyboard *keyboard = wl_resource_get_user_data(resource); - input_focus_remove_resource(&keyboard->focus, resource); } struct wl_resource * -keyboard_bind(struct keyboard *keyboard, - struct wl_client *client, - uint32_t version, uint32_t id) +keyboard_bind(struct keyboard *keyboard, struct wl_client *client, uint32_t version, uint32_t id) { struct wl_resource *client_resource; - client_resource = wl_resource_create(client, &wl_keyboard_interface, - version, id); - wl_resource_set_implementation(client_resource, &keyboard_implementation, - keyboard, &unbind); + client_resource = wl_resource_create(client, &wl_keyboard_interface, version, id); + wl_resource_set_implementation(client_resource, &keyboard_implementation, keyboard, &unbind); input_focus_add_resource(&keyboard->focus, client_resource); /* Subtract one to remove terminating NULL character. */ - wl_keyboard_send_keymap(client_resource, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, - keyboard->xkb.keymap.fd, - keyboard->xkb.keymap.size - 1); + wl_keyboard_send_keymap(client_resource, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keyboard->xkb.keymap.fd, keyboard->xkb.keymap.size - 1); - if (version >= 4) { - wl_keyboard_send_repeat_info(client_resource, - repeat_rate, repeat_delay); - } + if (version >= 4) + wl_keyboard_send_repeat_info(client_resource, repeat_rate, repeat_delay); return client_resource; } void -keyboard_handle_key(struct keyboard *keyboard, uint32_t time, - uint32_t value, uint32_t state) +keyboard_handle_key(struct keyboard *keyboard, uint32_t time, uint32_t value, uint32_t state) { struct key *key; struct keyboard_modifier_state modifier_state; @@ -280,10 +259,9 @@ keyboard_handle_key(struct keyboard *keyboard, uint32_t time, } } -/* Update XKB state. */ + /* Update XKB state. */ update_xkb_state: - direction = state == WL_KEYBOARD_KEY_STATE_PRESSED ? XKB_KEY_DOWN - : XKB_KEY_UP; + direction = state == WL_KEYBOARD_KEY_STATE_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP; xkb_state_update_key(xkb->state, XKB_KEY(value), direction); modifier_state.depressed = xkb_state_serialize_mods(xkb->state, XKB_STATE_DEPRESSED); @@ -292,11 +270,11 @@ update_xkb_state: modifier_state.group = xkb_state_serialize_layout(xkb->state, XKB_STATE_LAYOUT_EFFECTIVE); if (modifier_state.depressed != keyboard->modifier_state.depressed - || modifier_state.latched != keyboard->modifier_state.latched - || modifier_state.locked != keyboard->modifier_state.locked - || modifier_state.group != keyboard->modifier_state.group) { - uint32_t mods_active = modifier_state.depressed - | modifier_state.latched; + || modifier_state.latched != keyboard->modifier_state.latched + || modifier_state.locked != keyboard->modifier_state.locked + || modifier_state.group != keyboard->modifier_state.group) + { + uint32_t mods_active = modifier_state.depressed | modifier_state.latched; /* Update keyboard modifier state. */ keyboard->modifier_state = modifier_state; diff --git a/libswc/keyboard.h b/libswc/keyboard.h @@ -45,10 +45,8 @@ struct keyboard_modifier_state { }; struct keyboard_handler { - bool (*key)(struct keyboard *keyboard, uint32_t time, - struct key *key, uint32_t state); - bool (*modifiers)(struct keyboard *keyboard, - const struct keyboard_modifier_state *state); + bool (*key)(struct keyboard *keyboard, uint32_t time, struct key *key, uint32_t state); + bool (*modifiers)(struct keyboard *keyboard, const struct keyboard_modifier_state *state); struct wl_list link; }; @@ -70,12 +68,8 @@ struct keyboard { bool keyboard_initialize(struct keyboard *keyboard); void keyboard_finalize(struct keyboard *keyboard); void keyboard_reset(struct keyboard *keyboard); -void keyboard_set_focus(struct keyboard *keyboard, - struct compositor_view *view); -struct wl_resource *keyboard_bind(struct keyboard *keyboard, - struct wl_client *client, - uint32_t version, uint32_t id); -void keyboard_handle_key(struct keyboard *keyboard, uint32_t time, - uint32_t key, uint32_t state); +void keyboard_set_focus(struct keyboard *keyboard, struct compositor_view *view); +struct wl_resource *keyboard_bind(struct keyboard *keyboard, struct wl_client *client, uint32_t version, uint32_t id); +void keyboard_handle_key(struct keyboard *keyboard, uint32_t time, uint32_t key, uint32_t state); #endif diff --git a/libswc/launch.c b/libswc/launch.c @@ -30,8 +30,7 @@ #include <unistd.h> #include <wayland-server.h> -static struct - { +static struct { int socket; struct wl_event_source *source; uint32_t next_serial; @@ -61,7 +60,6 @@ handle_data(int fd, uint32_t mask, void *data) if (receive_fd(fd, NULL, &event, sizeof event) != -1) handle_event(&event); - return 1; } @@ -78,8 +76,7 @@ launch_initialize(void) if (*end != '\0') return false; - launch.source = wl_event_loop_add_fd(swc.event_loop, launch.socket, - WL_EVENT_READABLE, &handle_data, NULL); + launch.source = wl_event_loop_add_fd(swc.event_loop, launch.socket, WL_EVENT_READABLE, &handle_data, NULL); if (!launch.source) return false; @@ -95,9 +92,7 @@ launch_finalize(void) } static bool -send_request(struct swc_launch_request *request, size_t size, - struct swc_launch_event *event, - int out_fd, int *in_fd) +send_request(struct swc_launch_request *request, size_t size, struct swc_launch_event *event, int out_fd, int *in_fd) { request->serial = ++launch.next_serial; @@ -105,11 +100,8 @@ send_request(struct swc_launch_request *request, size_t size, return false; while (receive_fd(launch.socket, in_fd, event, sizeof *event) != -1) { - if (event->type == SWC_LAUNCH_EVENT_RESPONSE - && event->serial == request->serial) { + if (event->type == SWC_LAUNCH_EVENT_RESPONSE && event->serial == request->serial) return true; - } - handle_event(event); } diff --git a/libswc/launch.h b/libswc/launch.h @@ -29,7 +29,6 @@ bool launch_initialize(void); void launch_finalize(void); - int launch_open_device(const char *path, int flags); bool launch_activate_vt(unsigned vt); diff --git a/libswc/mode.c b/libswc/mode.c @@ -30,9 +30,7 @@ mode_initialize(struct mode *mode, drmModeModeInfo *mode_info) mode->height = mode_info->vdisplay; mode->refresh = mode_info->vrefresh * 1000; mode->preferred = mode_info->type & DRM_MODE_TYPE_PREFERRED; - mode->info = *mode_info; - return true; } @@ -45,6 +43,6 @@ bool mode_equal(const struct mode *mode1, const struct mode *mode2) { return mode1->width == mode2->width - && mode1->height == mode2->height - && mode1->refresh == mode2->refresh; + && mode1->height == mode2->height + && mode1->refresh == mode2->refresh; } diff --git a/libswc/mode.h b/libswc/mode.h @@ -42,7 +42,6 @@ struct mode { bool mode_initialize(struct mode *mode, drmModeModeInfo *mode_info); void mode_finish(struct mode *mode); - bool mode_equal(const struct mode *mode1, const struct mode *mode2); #endif diff --git a/libswc/output.c b/libswc/output.c @@ -12,8 +12,7 @@ #include <xf86drm.h> static void -bind_output(struct wl_client *client, void *data, - uint32_t version, uint32_t id) +bind_output(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct output *output = data; struct screen *screen = output->screen; @@ -35,8 +34,8 @@ bind_output(struct wl_client *client, void *data, wl_list_insert(&output->resources, wl_resource_get_link(resource)); wl_output_send_geometry(resource, screen->base.geometry.x, screen->base.geometry.y, - output->physical_width, output->physical_height, 0, "unknown", - "unknown", WL_OUTPUT_TRANSFORM_NORMAL); + output->physical_width, output->physical_height, + 0, "unknown", "unknown", WL_OUTPUT_TRANSFORM_NORMAL); wl_array_for_each (mode, &output->modes) { flags = 0; @@ -45,8 +44,7 @@ bind_output(struct wl_client *client, void *data, if (mode_equal(&screen->planes.framebuffer.mode, mode)) flags |= WL_OUTPUT_MODE_CURRENT; - wl_output_send_mode(resource, flags, - mode->width, mode->height, mode->refresh); + wl_output_send_mode(resource, flags, mode->width, mode->height, mode->refresh); } if (version >= 2) @@ -58,15 +56,14 @@ output_new(drmModeConnectorPtr connector) { struct output *output; struct mode *modes; - uint32_t index; + uint32_t i; if (!(output = malloc(sizeof *output))) { ERROR("Failed to allocated output\n"); goto error0; } - output->global = wl_global_create(swc.display, &wl_output_interface, 2, - output, &bind_output); + output->global = wl_global_create(swc.display, &wl_output_interface, 2, output, &bind_output); if (!output->global) { ERROR("Failed to create output global\n"); @@ -88,11 +85,11 @@ output_new(drmModeConnectorPtr connector) if (!modes) goto error2; - for (index = 0; index < connector->count_modes; ++index) { - mode_initialize(&modes[index], &connector->modes[index]); + for (i = 0; i < connector->count_modes; ++i) { + mode_initialize(&modes[i], &connector->modes[i]); - if (modes[index].preferred) - output->preferred_mode = &modes[index]; + if (modes[i].preferred) + output->preferred_mode = &modes[i]; } return output; diff --git a/libswc/panel.c b/libswc/panel.c @@ -53,8 +53,7 @@ static void update_position(struct panel *panel) { int32_t x, y; - struct swc_rectangle *screen = &panel->screen->base.geometry, - *view = &panel->view->base.geometry; + struct swc_rectangle *screen = &panel->screen->base.geometry, *view = &panel->view->base.geometry; switch (panel->edge) { case SWC_PANEL_EDGE_TOP: @@ -81,17 +80,17 @@ update_position(struct panel *panel) } static void -dock(struct wl_client *client, struct wl_resource *resource, - uint32_t edge, struct wl_resource *screen_resource, - uint32_t focus) +dock(struct wl_client *client, struct wl_resource *resource, uint32_t edge, struct wl_resource *screen_resource, uint32_t focus) { struct panel *panel = wl_resource_get_user_data(resource); - struct screen *screen = screen_resource - ? wl_resource_get_user_data(screen_resource) - : wl_container_of(swc.screens.next, screen, link); - bool screen_changed = screen != panel->screen; + struct screen *screen; uint32_t length; + if (screen_resource) + screen = wl_resource_get_user_data(screen_resource); + else + screen = wl_container_of(swc.screens.next, screen, link); + switch (edge) { case SWC_PANEL_EDGE_TOP: case SWC_PANEL_EDGE_BOTTOM: @@ -105,7 +104,7 @@ dock(struct wl_client *client, struct wl_resource *resource, return; } - if (panel->screen && screen_changed) { + if (panel->screen && screen != panel->screen) { wl_list_remove(&panel->modifier.link); screen_update_usable_geometry(panel->screen); } @@ -125,56 +124,51 @@ dock(struct wl_client *client, struct wl_resource *resource, } static void -set_offset(struct wl_client *client, struct wl_resource *resource, - uint32_t offset) +set_offset(struct wl_client *client, struct wl_resource *resource, uint32_t offset) { struct panel *panel = wl_resource_get_user_data(resource); panel->offset = offset; - if (panel->docked) update_position(panel); } static void -set_strut(struct wl_client *client, struct wl_resource *resource, - uint32_t size, uint32_t begin, uint32_t end) +set_strut(struct wl_client *client, struct wl_resource *resource, uint32_t size, uint32_t begin, uint32_t end) { struct panel *panel = wl_resource_get_user_data(resource); panel->strut_size = size; - if (panel->docked) screen_update_usable_geometry(panel->screen); } static const struct swc_panel_interface panel_implementation = { - .dock = &dock, - .set_offset = &set_offset, - .set_strut = &set_strut + .dock = dock, + .set_offset = set_offset, + .set_strut = set_strut, }; static void -handle_resize(struct view_handler *handler, - uint32_t old_width, uint32_t old_height) +handle_resize(struct view_handler *handler, uint32_t old_width, uint32_t old_height) { struct panel *panel = wl_container_of(handler, panel, view_handler); - update_position(panel); } static const struct view_handler_impl view_handler_impl = { - .resize = &handle_resize, + .resize = handle_resize, }; static void -modify(struct screen_modifier *modifier, - const struct swc_rectangle *geometry, - pixman_region32_t *usable) +modify(struct screen_modifier *modifier, const struct swc_rectangle *geom, pixman_region32_t *usable) { struct panel *panel = wl_container_of(modifier, panel, modifier); pixman_box32_t box = { - .x1 = geometry->x, .y1 = geometry->y, .x2 = geometry->x + geometry->width, .y2 = geometry->y + geometry->height + .x1 = geom->x, + .y1 = geom->y, + .x2 = geom->x + geom->width, + .y2 = geom->y + geom->height }; assert(panel->docked); @@ -184,18 +178,16 @@ modify(struct screen_modifier *modifier, switch (panel->edge) { case SWC_PANEL_EDGE_TOP: - box.y1 = MAX(box.y1, geometry->y + panel->strut_size); + box.y1 = MAX(box.y1, geom->y + panel->strut_size); break; case SWC_PANEL_EDGE_BOTTOM: - box.y2 = MIN(box.y2, geometry->y + geometry->height - - panel->strut_size); + box.y2 = MIN(box.y2, geom->y + geom->height - panel->strut_size); break; case SWC_PANEL_EDGE_LEFT: - box.x1 = MAX(box.x1, geometry->x + panel->strut_size); + box.x1 = MAX(box.x1, geom->x + panel->strut_size); break; case SWC_PANEL_EDGE_RIGHT: - box.x2 = MIN(box.x2, geometry->x + geometry->width - - panel->strut_size); + box.x2 = MIN(box.x2, geom->x + geom->width - panel->strut_size); break; } @@ -223,13 +215,11 @@ static void handle_surface_destroy(struct wl_listener *listener, void *data) { struct panel *panel = wl_container_of(listener, panel, surface_destroy_listener); - wl_resource_destroy(panel->resource); } struct panel * -panel_new(struct wl_client *client, uint32_t version, - uint32_t id, struct surface *surface) +panel_new(struct wl_client *client, uint32_t version, uint32_t id, struct surface *surface) { struct panel *panel; @@ -238,8 +228,7 @@ panel_new(struct wl_client *client, uint32_t version, if (!panel) goto error0; - panel->resource = wl_resource_create(client, &swc_panel_interface, - version, id); + panel->resource = wl_resource_create(client, &swc_panel_interface, version, id); if (!panel->resource) goto error1; @@ -247,9 +236,7 @@ panel_new(struct wl_client *client, uint32_t version, if (!(panel->view = compositor_create_view(surface))) goto error2; - wl_resource_set_implementation(panel->resource, &panel_implementation, - panel, &destroy_panel); - + wl_resource_set_implementation(panel->resource, &panel_implementation, panel, &destroy_panel); panel->surface_destroy_listener.notify = &handle_surface_destroy; panel->view_handler.impl = &view_handler_impl; panel->modifier.modify = &modify; @@ -257,10 +244,8 @@ panel_new(struct wl_client *client, uint32_t version, panel->offset = 0; panel->strut_size = 0; panel->docked = false; - wl_list_insert(&panel->view->base.handlers, &panel->view_handler.link); - wl_resource_add_destroy_listener(surface->resource, - &panel->surface_destroy_listener); + wl_resource_add_destroy_listener(surface->resource, &panel->surface_destroy_listener); return panel; diff --git a/libswc/panel.h b/libswc/panel.h @@ -24,12 +24,11 @@ #ifndef SWC_PANEL_H #define SWC_PANEL_H -#include "screen.h" +#include <stdint.h> -#include <stdbool.h> -#include <wayland-server.h> +struct surface; +struct wl_client; -struct panel *panel_new(struct wl_client *client, uint32_t version, - uint32_t id, struct surface *surface); +struct panel *panel_new(struct wl_client *client, uint32_t version, uint32_t id, struct surface *surface); #endif diff --git a/libswc/panel_manager.c b/libswc/panel_manager.c @@ -28,15 +28,12 @@ #include <wayland-server.h> #include "protocol/swc-server-protocol.h" -static struct - { +static struct { struct wl_global *global; } panel_manager; static void -create_panel(struct wl_client *client, - struct wl_resource *resource, uint32_t id, - struct wl_resource *surface_resource) +create_panel(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource) { struct surface *surface = wl_resource_get_user_data(surface_resource); @@ -45,30 +42,25 @@ create_panel(struct wl_client *client, } static const struct swc_panel_manager_interface panel_manager_implementation = { - .create_panel = &create_panel + .create_panel = create_panel, }; static void -bind_panel_manager(struct wl_client *client, void *data, - uint32_t version, uint32_t id) +bind_panel_manager(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wl_resource *resource; if (version > 1) version = 1; - resource = wl_resource_create(client, &swc_panel_manager_interface, - version, id); - wl_resource_set_implementation(resource, &panel_manager_implementation, - NULL, NULL); + resource = wl_resource_create(client, &swc_panel_manager_interface, version, id); + wl_resource_set_implementation(resource, &panel_manager_implementation, NULL, NULL); } bool panel_manager_initialize(void) { - panel_manager.global = wl_global_create(swc.display, - &swc_panel_manager_interface, 1, - NULL, &bind_panel_manager); + panel_manager.global = wl_global_create(swc.display, &swc_panel_manager_interface, 1, NULL, &bind_panel_manager); if (!panel_manager.global) return false; @@ -81,5 +73,3 @@ panel_manager_finalize(void) { wl_global_destroy(panel_manager.global); } - -// vim: fdm=syntax fo=croql et sw=4 sts=4 ts=8 diff --git a/libswc/pointer.c b/libswc/pointer.c @@ -35,8 +35,7 @@ #include <wld/wld.h> static void -enter(struct input_focus_handler *handler, - struct wl_resource *resource, struct compositor_view *view) +enter(struct input_focus_handler *handler, struct wl_resource *resource, struct compositor_view *view) { struct pointer *pointer = wl_container_of(handler, pointer, focus_handler); uint32_t serial; @@ -45,24 +44,20 @@ enter(struct input_focus_handler *handler, serial = wl_display_next_serial(swc.display); surface_x = pointer->x - wl_fixed_from_int(view->base.geometry.x); surface_y = pointer->y - wl_fixed_from_int(view->base.geometry.y); - wl_pointer_send_enter(resource, serial, view->surface->resource, - surface_x, surface_y); + wl_pointer_send_enter(resource, serial, view->surface->resource, surface_x, surface_y); } static void -leave(struct input_focus_handler *handler, - struct wl_resource *resource, struct compositor_view *view) +leave(struct input_focus_handler *handler, struct wl_resource *resource, struct compositor_view *view) { uint32_t serial; serial = wl_display_next_serial(swc.display); - wl_pointer_send_leave(resource, serial, view->surface->resource); } static void -handle_cursor_surface_destroy(struct wl_listener *listener, - void *data) +handle_cursor_surface_destroy(struct wl_listener *listener, void *data) { struct pointer *pointer = wl_container_of(listener, pointer, cursor.destroy_listener); @@ -88,10 +83,8 @@ attach(struct view *view, struct wld_buffer *buffer) wld_set_target_buffer(swc.shm->renderer, pointer->cursor.buffer); wld_fill_rectangle(swc.shm->renderer, 0x00000000, 0, 0, 64, 64); - if (buffer) { - wld_copy_rectangle(swc.shm->renderer, buffer, 0, 0, 0, 0, - buffer->width, buffer->height); - } + if (buffer) + wld_copy_rectangle(swc.shm->renderer, buffer, 0, 0, 0, 0, buffer->width, buffer->height); wld_flush(swc.shm->renderer); @@ -114,69 +107,66 @@ move(struct view *view, int32_t x, int32_t y) if (view_set_position(view, x, y)) view_update_screens(view); - wl_list_for_each (screen, &swc.screens, link) { - view_move(&screen->planes.cursor.view, - view->geometry.x, view->geometry.y); - } + wl_list_for_each (screen, &swc.screens, link) + view_move(&screen->planes.cursor.view, view->geometry.x, view->geometry.y); return true; } static const struct view_impl view_impl = { - .update = &update, - .attach = &attach, - .move = &move, + .update = update, + .attach = attach, + .move = move, }; static inline void update_cursor(struct pointer *pointer) { - view_move(&pointer->cursor.view, - wl_fixed_to_int(pointer->x) - pointer->cursor.hotspot.x, - wl_fixed_to_int(pointer->y) - pointer->cursor.hotspot.y); + int32_t x = wl_fixed_to_int(pointer->x) - pointer->cursor.hotspot.x, + y = wl_fixed_to_int(pointer->y) - pointer->cursor.hotspot.y; + + view_move(&pointer->cursor.view, x, y); } void pointer_set_cursor(struct pointer *pointer, uint32_t id) { struct cursor *cursor = &cursor_metadata[id]; - union wld_object object = {.ptr = &cursor_data[cursor->offset] }; + union wld_object object = { .ptr = &cursor_data[cursor->offset] }; + struct wld_buffer *buffer; if (pointer->cursor.internal_buffer) wld_buffer_unreference(pointer->cursor.internal_buffer); - pointer->cursor.internal_buffer = wld_import_buffer(swc.shm->context, WLD_OBJECT_DATA, object, - cursor->width, cursor->height, WLD_FORMAT_ARGB8888, cursor->width * 4); + buffer = wld_import_buffer(swc.shm->context, WLD_OBJECT_DATA, object, + cursor->width, cursor->height, WLD_FORMAT_ARGB8888, cursor->width * 4); - if (!pointer->cursor.internal_buffer) { + if (!buffer) { ERROR("Failed to create cursor buffer\n"); return; } + pointer->cursor.internal_buffer = buffer; pointer->cursor.hotspot.x = cursor->hotspot_x; pointer->cursor.hotspot.y = cursor->hotspot_y; update_cursor(pointer); - view_attach(&pointer->cursor.view, pointer->cursor.internal_buffer); + view_attach(&pointer->cursor.view, buffer); } static bool -client_handle_button(struct pointer_handler *handler, uint32_t time, - struct button *button, uint32_t state) +client_handle_button(struct pointer_handler *handler, uint32_t time, struct button *button, uint32_t state) { struct pointer *pointer = wl_container_of(handler, pointer, client_handler); if (!pointer->focus.resource) return false; - wl_pointer_send_button(pointer->focus.resource, button->press.serial, time, - button->press.value, state); - + wl_pointer_send_button(pointer->focus.resource, button->press.serial, time, button->press.value, state); return true; } static bool -client_handle_axis(struct pointer_handler *handler, - uint32_t time, uint32_t axis, wl_fixed_t amount) +client_handle_axis(struct pointer_handler *handler, uint32_t time, uint32_t axis, wl_fixed_t amount) { struct pointer *pointer = wl_container_of(handler, pointer, client_handler); @@ -184,41 +174,39 @@ client_handle_axis(struct pointer_handler *handler, return false; wl_pointer_send_axis(pointer->focus.resource, time, axis, amount); - return true; } static bool -client_handle_motion(struct pointer_handler *handler, - uint32_t time, wl_fixed_t x, wl_fixed_t y) +client_handle_motion(struct pointer_handler *handler, uint32_t time, wl_fixed_t x, wl_fixed_t y) { struct pointer *pointer = wl_container_of(handler, pointer, client_handler); + wl_fixed_t sx, sy; if (!pointer->focus.resource) return false; - wl_pointer_send_motion(pointer->focus.resource, time, - x - wl_fixed_from_int(pointer->focus.view->base.geometry.x), - y - wl_fixed_from_int(pointer->focus.view->base.geometry.y)); - + sx = x - wl_fixed_from_int(pointer->focus.view->base.geometry.x); + sy = y - wl_fixed_from_int(pointer->focus.view->base.geometry.y); + wl_pointer_send_motion(pointer->focus.resource, time, sx, sy); return true; } bool pointer_initialize(struct pointer *pointer) { - struct screen *screen; + struct screen *screen = wl_container_of(swc.screens.next, screen, link); + struct swc_rectangle *geom = &screen->base.geometry; /* Center cursor in the geometry of the first screen. */ screen = wl_container_of(swc.screens.next, screen, link); - pointer->x = wl_fixed_from_int(screen->base.geometry.x + screen->base.geometry.width / 2); - pointer->y = wl_fixed_from_int(screen->base.geometry.y + screen->base.geometry.height / 2); - - pointer->focus_handler.enter = &enter; - pointer->focus_handler.leave = &leave; - pointer->client_handler.button = &client_handle_button; - pointer->client_handler.axis = &client_handle_axis; - pointer->client_handler.motion = &client_handle_motion; + pointer->x = wl_fixed_from_int(geom->x + geom->width / 2); + pointer->y = wl_fixed_from_int(geom->y + geom->height / 2); + pointer->focus_handler.enter = enter; + pointer->focus_handler.leave = leave; + pointer->client_handler.button = client_handle_button; + pointer->client_handler.axis = client_handle_axis; + pointer->client_handler.motion = client_handle_motion; wl_list_init(&pointer->handlers); wl_list_insert(&pointer->handlers, &pointer->client_handler.link); wl_array_init(&pointer->buttons); @@ -257,8 +245,7 @@ pointer_set_focus(struct pointer *pointer, struct compositor_view *view) } static void -clip_position(struct pointer *pointer, - wl_fixed_t fx, wl_fixed_t fy) +clip_position(struct pointer *pointer, wl_fixed_t fx, wl_fixed_t fy) { int32_t x, y, last_x, last_y; pixman_box32_t box; @@ -269,8 +256,7 @@ clip_position(struct pointer *pointer, last_y = wl_fixed_to_int(pointer->y); if (!pixman_region32_contains_point(&pointer->region, x, y, NULL)) { - assert(pixman_region32_contains_point(&pointer->region, - last_x, last_y, &box)); + assert(pixman_region32_contains_point(&pointer->region, last_x, last_y, &box)); /* Do some clipping. */ x = MAX(MIN(x, box.x2 - 1), box.x1); @@ -289,10 +275,8 @@ pointer_set_region(struct pointer *pointer, pixman_region32_t *region) } static void -set_cursor(struct wl_client *client, - struct wl_resource *resource, uint32_t serial, - struct wl_resource *surface_resource, - int32_t hotspot_x, int32_t hotspot_y) +set_cursor(struct wl_client *client, struct wl_resource *resource, + uint32_t serial, struct wl_resource *surface_resource, int32_t hotspot_x, int32_t hotspot_y) { struct pointer *pointer = wl_resource_get_user_data(resource); struct surface *surface; @@ -303,16 +287,14 @@ set_cursor(struct wl_client *client, if (pointer->cursor.surface) wl_list_remove(&pointer->cursor.destroy_listener.link); - surface = surface_resource ? wl_resource_get_user_data(surface_resource) - : NULL; + surface = surface_resource ? wl_resource_get_user_data(surface_resource) : NULL; pointer->cursor.surface = surface; pointer->cursor.hotspot.x = hotspot_x; pointer->cursor.hotspot.y = hotspot_y; if (surface) { surface_set_view(surface, &pointer->cursor.view); - wl_resource_add_destroy_listener(surface->resource, - &pointer->cursor.destroy_listener); + wl_resource_add_destroy_listener(surface->resource, &pointer->cursor.destroy_listener); update_cursor(pointer); } } @@ -324,29 +306,24 @@ release(struct wl_client *client, struct wl_resource *resource) } static struct wl_pointer_interface pointer_implementation = { - .set_cursor = &set_cursor, - .release = &release, + .set_cursor = set_cursor, + .release = release, }; static void unbind(struct wl_resource *resource) { struct pointer *pointer = wl_resource_get_user_data(resource); - input_focus_remove_resource(&pointer->focus, resource); } struct wl_resource * -pointer_bind(struct pointer *pointer, - struct wl_client *client, - uint32_t version, uint32_t id) +pointer_bind(struct pointer *pointer, struct wl_client *client, uint32_t version, uint32_t id) { struct wl_resource *client_resource; - client_resource = wl_resource_create(client, &wl_pointer_interface, - version, id); - wl_resource_set_implementation(client_resource, &pointer_implementation, - pointer, &unbind); + client_resource = wl_resource_create(client, &wl_pointer_interface, version, id); + wl_resource_set_implementation(client_resource, &pointer_implementation, pointer, &unbind); input_focus_add_resource(&pointer->focus, client_resource); return client_resource; @@ -366,8 +343,7 @@ pointer_get_button(struct pointer *pointer, uint32_t serial) } void -pointer_handle_button(struct pointer *pointer, uint32_t time, - uint32_t value, uint32_t state) +pointer_handle_button(struct pointer *pointer, uint32_t time, uint32_t value, uint32_t state) { struct pointer_handler *handler; struct button *button; @@ -380,8 +356,7 @@ pointer_handle_button(struct pointer *pointer, uint32_t time, if (button->press.value == value) { if (button->handler) { button->press.serial = serial; - button->handler->button(button->handler, time, - button, state); + button->handler->button(button->handler, time, button, state); } array_remove(&pointer->buttons, button, sizeof *button); @@ -408,8 +383,7 @@ pointer_handle_button(struct pointer *pointer, uint32_t time, } void -pointer_handle_axis(struct pointer *pointer, uint32_t time, - uint32_t axis, wl_fixed_t amount) +pointer_handle_axis(struct pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t amount) { struct pointer_handler *handler; @@ -420,17 +394,15 @@ pointer_handle_axis(struct pointer *pointer, uint32_t time, } void -pointer_handle_relative_motion(struct pointer *pointer, uint32_t time, - wl_fixed_t dx, wl_fixed_t dy) +pointer_handle_relative_motion(struct pointer *pointer, uint32_t time, wl_fixed_t dx, wl_fixed_t dy) { struct pointer_handler *handler; clip_position(pointer, pointer->x + dx, pointer->y + dy); wl_list_for_each (handler, &pointer->handlers, link) { - if (handler->motion && handler->motion(handler, time, pointer->x, pointer->y)) { + if (handler->motion && handler->motion(handler, time, pointer->x, pointer->y)) break; - } } update_cursor(pointer); diff --git a/libswc/pointer.h b/libswc/pointer.h @@ -37,12 +37,9 @@ struct button { }; struct pointer_handler { - bool (*motion)(struct pointer_handler *handler, uint32_t time, - wl_fixed_t x, wl_fixed_t y); - bool (*button)(struct pointer_handler *handler, uint32_t time, - struct button *button, uint32_t state); - bool (*axis)(struct pointer_handler *handler, uint32_t time, - enum wl_pointer_axis axis, wl_fixed_t amount); + bool (*motion)(struct pointer_handler *handler, uint32_t time, wl_fixed_t x, wl_fixed_t y); + bool (*button)(struct pointer_handler *handler, uint32_t time, struct button *button, uint32_t state); + bool (*axis)(struct pointer_handler *handler, uint32_t time, enum wl_pointer_axis axis, wl_fixed_t amount); struct wl_list link; }; @@ -51,8 +48,7 @@ struct pointer { struct input_focus focus; struct input_focus_handler focus_handler; - struct - { + struct { struct view view; struct surface *surface; struct wl_listener destroy_listener; @@ -61,8 +57,7 @@ struct pointer { /* Used for cursors set with pointer_set_cursor */ struct wld_buffer *internal_buffer; - struct - { + struct { int32_t x, y; } hotspot; } cursor; @@ -83,14 +78,9 @@ void pointer_set_cursor(struct pointer *pointer, uint32_t id); struct button *pointer_get_button(struct pointer *pointer, uint32_t serial); -struct wl_resource *pointer_bind(struct pointer *pointer, - struct wl_client *client, - uint32_t version, uint32_t id); -void pointer_handle_button(struct pointer *pointer, uint32_t time, - uint32_t button, uint32_t state); -void pointer_handle_axis(struct pointer *pointer, uint32_t time, - uint32_t axis, wl_fixed_t amount); -void pointer_handle_relative_motion(struct pointer *pointer, uint32_t time, - wl_fixed_t dx, wl_fixed_t dy); +struct wl_resource *pointer_bind(struct pointer *pointer, struct wl_client *client, uint32_t version, uint32_t id); +void pointer_handle_button(struct pointer *pointer, uint32_t time, uint32_t button, uint32_t state); +void pointer_handle_axis(struct pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t amount); +void pointer_handle_relative_motion(struct pointer *pointer, uint32_t time, wl_fixed_t dx, wl_fixed_t dy); #endif diff --git a/libswc/region.c b/libswc/region.c @@ -10,18 +10,14 @@ destroy(struct wl_client *client, struct wl_resource *resource) } static void -add(struct wl_client *client, struct wl_resource *resource, - int32_t x, int32_t y, int32_t width, int32_t height) +add(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) { struct region *region = wl_resource_get_user_data(resource); - - pixman_region32_union_rect(&region->region, &region->region, - x, y, width, height); + pixman_region32_union_rect(&region->region, &region->region, x, y, width, height); } static void -subtract(struct wl_client *client, struct wl_resource *resource, - int32_t x, int32_t y, int32_t width, int32_t height) +subtract(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) { struct region *region = wl_resource_get_user_data(resource); pixman_region32_t operand; @@ -31,9 +27,9 @@ subtract(struct wl_client *client, struct wl_resource *resource, } static const struct wl_region_interface region_implementation = { - .destroy = &destroy, - .add = &add, - .subtract = &subtract + .destroy = destroy, + .add = add, + .subtract = subtract, }; static void @@ -41,15 +37,12 @@ region_destroy(struct wl_resource *resource) { struct region *region = wl_resource_get_user_data(resource); - /* Finish the region. */ pixman_region32_fini(&region->region); - free(region); } struct region * -region_new(struct wl_client *client, - uint32_t version, uint32_t id) +region_new(struct wl_client *client, uint32_t version, uint32_t id) { struct region *region; @@ -58,14 +51,9 @@ region_new(struct wl_client *client, if (!region) return NULL; - /* Initialize the region. */ pixman_region32_init(&region->region); - - /* Add the region to the client. */ - region->resource = wl_resource_create(client, &wl_region_interface, - version, id); - wl_resource_set_implementation(region->resource, &region_implementation, - region, &region_destroy); + region->resource = wl_resource_create(client, &wl_region_interface, version, id); + wl_resource_set_implementation(region->resource, &region_implementation, region, &region_destroy); return region; } diff --git a/libswc/region.h b/libswc/region.h @@ -11,7 +11,6 @@ struct region { pixman_region32_t region; }; -struct region *region_new(struct wl_client *client, - uint32_t version, uint32_t id); +struct region *region_new(struct wl_client *client, uint32_t version, uint32_t id); #endif diff --git a/libswc/screen.c b/libswc/screen.c @@ -39,18 +39,14 @@ static struct screen *active_screen; static const struct swc_screen_handler null_handler; -static bool handle_motion(struct pointer_handler *handler, uint32_t time, - wl_fixed_t x, wl_fixed_t y); +static bool handle_motion(struct pointer_handler *handler, uint32_t time, wl_fixed_t x, wl_fixed_t y); struct pointer_handler screens_pointer_handler = { - .motion = &handle_motion + .motion = handle_motion, }; -EXPORT -void -swc_screen_set_handler(struct swc_screen *base, - const struct swc_screen_handler *handler, - void *data) +EXPORT void +swc_screen_set_handler(struct swc_screen *base, const struct swc_screen_handler *handler, void *data) { struct screen *screen = INTERNAL(base); @@ -82,8 +78,7 @@ screens_finalize(void) } static void -bind_screen(struct wl_client *client, void *data, - uint32_t version, uint32_t id) +bind_screen(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct screen *screen = data; struct wl_resource *resource; @@ -115,23 +110,19 @@ screen_new(uint32_t crtc, struct output *output) if (!(screen = malloc(sizeof *screen))) goto error0; - screen->global = wl_global_create(swc.display, &swc_screen_interface, 1, - screen, &bind_screen); + screen->global = wl_global_create(swc.display, &swc_screen_interface, 1, screen, &bind_screen); if (!screen->global) { ERROR("Failed to create screen global\n"); goto error1; } - if (!framebuffer_plane_initialize(&screen->planes.framebuffer, crtc, - output->preferred_mode, - &output->connector, 1)) { + if (!framebuffer_plane_initialize(&screen->planes.framebuffer, crtc, output->preferred_mode, &output->connector, 1)) { ERROR("Failed to initialize framebuffer plane\n"); goto error2; } - if (!cursor_plane_initialize(&screen->planes.cursor, crtc, - &screen->base.geometry)) { + if (!cursor_plane_initialize(&screen->planes.cursor, crtc, &screen->base.geometry)) { ERROR("Failed to initialize cursor plane\n"); goto error3; } @@ -184,26 +175,25 @@ screen_update_usable_geometry(struct screen *screen) pixman_region32_t total_usable, usable; pixman_box32_t *extents; struct screen_modifier *modifier; + struct swc_rectangle *geom = &screen->base.geometry; DEBUG("Updating usable geometry\n"); - pixman_region32_init_rect(&total_usable, - screen->base.geometry.x, screen->base.geometry.y, - screen->base.geometry.width, - screen->base.geometry.height); + pixman_region32_init_rect(&total_usable, geom->x, geom->y, geom->width, geom->height); pixman_region32_init(&usable); wl_list_for_each (modifier, &screen->modifiers, link) { - modifier->modify(modifier, &screen->base.geometry, &usable); + modifier->modify(modifier, geom, &usable); pixman_region32_intersect(&total_usable, &total_usable, &usable); } extents = pixman_region32_extents(&total_usable); if (extents->x1 != screen->base.usable_geometry.x - || extents->y1 != screen->base.usable_geometry.y - || (extents->x2 - extents->x1) != screen->base.usable_geometry.width - || (extents->y2 - extents->y1) != screen->base.usable_geometry.height) { + || extents->y1 != screen->base.usable_geometry.y + || (extents->x2 - extents->x1) != screen->base.usable_geometry.width + || (extents->y2 - extents->y1) != screen->base.usable_geometry.height) + { screen->base.usable_geometry.x = extents->x1; screen->base.usable_geometry.y = extents->y1; screen->base.usable_geometry.width = extents->x2 - extents->x1; @@ -215,8 +205,7 @@ screen_update_usable_geometry(struct screen *screen) } bool -handle_motion(struct pointer_handler *handler, uint32_t time, - wl_fixed_t fx, wl_fixed_t fy) +handle_motion(struct pointer_handler *handler, uint32_t time, wl_fixed_t fx, wl_fixed_t fy) { struct screen *screen; int32_t x = wl_fixed_to_int(fx), y = wl_fixed_to_int(fy); diff --git a/libswc/screen.h b/libswc/screen.h @@ -35,12 +35,10 @@ struct pixman_region32; struct screen_modifier { /** - * Takes the screen geometry and sets 'usable' to the usable region of the - * screen. 'usable' is an already initialized pixman region. - */ - void (*modify)(struct screen_modifier *modifier, - const struct swc_rectangle *geometry, - struct pixman_region32 *usable); + * Takes the screen geometry and sets 'usable' to the usable region of the + * screen. 'usable' is an already initialized pixman region. + */ + void (*modify)(struct screen_modifier *modifier, const struct swc_rectangle *geometry, struct pixman_region32 *usable); struct wl_list link; }; @@ -53,8 +51,7 @@ struct screen { struct wl_signal destroy_signal; uint8_t id; - struct - { + struct { struct framebuffer_plane framebuffer; struct cursor_plane cursor; } planes; diff --git a/libswc/seat.c b/libswc/seat.c @@ -39,12 +39,11 @@ #include <string.h> #include <unistd.h> #ifdef ENABLE_LIBINPUT -#include <libudev.h> -#include <libinput.h> +# include <libudev.h> +# include <libinput.h> #endif -static struct - { +static struct { char *name; uint32_t capabilities; @@ -69,7 +68,7 @@ static struct const struct swc_seat swc_seat = { .pointer = &seat.pointer, .keyboard = &seat.keyboard, - .data_device = &seat.data_device + .data_device = &seat.data_device, }; static void @@ -97,66 +96,62 @@ handle_relative_motion(uint32_t time, wl_fixed_t dx, wl_fixed_t dy) } static void -handle_keyboard_focus_event(struct wl_listener *listener, - void *data) +handle_keyboard_focus_event(struct wl_listener *listener, void *data) { - struct event *event = data; - struct input_focus_event_data *event_data = event->data; + struct event *ev = data; + struct input_focus_event_data *event_data = ev->data; - switch (event->type) { - case INPUT_FOCUS_EVENT_CHANGED: - if (event_data->new) { - struct wl_client *client = wl_resource_get_client(event_data->new->surface->resource); + if (ev->type != INPUT_FOCUS_EVENT_CHANGED) + return; - /* Offer the selection to the new focus. */ - data_device_offer_selection(&seat.data_device, client); - } - break; + if (event_data->new) { + struct wl_client *client = wl_resource_get_client(event_data->new->surface->resource); + + /* Offer the selection to the new focus. */ + data_device_offer_selection(&seat.data_device, client); } } static struct wl_listener keyboard_focus_listener = { - .notify = &handle_keyboard_focus_event + .notify = handle_keyboard_focus_event, }; static void handle_data_device_event(struct wl_listener *listener, void *data) { - struct event *event = data; + struct event *ev = data; - switch (event->type) { - case DATA_DEVICE_EVENT_SELECTION_CHANGED: - if (seat.keyboard.focus.resource) { - struct wl_client *client = wl_resource_get_client(seat.keyboard.focus.resource); - data_device_offer_selection(&seat.data_device, client); - } - break; + if (ev->type != DATA_DEVICE_EVENT_SELECTION_CHANGED) + return; + + if (seat.keyboard.focus.resource) { + struct wl_client *client = wl_resource_get_client(seat.keyboard.focus.resource); + data_device_offer_selection(&seat.data_device, client); } } static struct wl_listener data_device_listener = { - .notify = &handle_data_device_event + .notify = handle_data_device_event, }; static void handle_swc_event(struct wl_listener *listener, void *data) { - struct event *event = data; + struct event *ev = data; + struct evdev_device *device, *next; - switch (event->type) { + switch (ev->type) { case SWC_EVENT_DEACTIVATED: #ifdef ENABLE_LIBINPUT libinput_suspend(seat.libinput); #endif keyboard_reset(&seat.keyboard); break; - case SWC_EVENT_ACTIVATED: { + case SWC_EVENT_ACTIVATED: #ifdef ENABLE_LIBINPUT if (libinput_resume(seat.libinput) != 0) WARNING("Failed to resume libinput context\n"); #else - struct evdev_device *device, *next; - /* Re-open all input devices */ wl_list_for_each_safe (device, next, &seat.devices, link) { if (!evdev_device_reopen(device)) { @@ -167,41 +162,35 @@ handle_swc_event(struct wl_listener *listener, void *data) #endif break; } - } } /* Wayland Seat Interface */ static void -get_pointer(struct wl_client *client, - struct wl_resource *resource, uint32_t id) +get_pointer(struct wl_client *client, struct wl_resource *resource, uint32_t id) { pointer_bind(&seat.pointer, client, wl_resource_get_version(resource), id); } static void -get_keyboard(struct wl_client *client, - struct wl_resource *resource, uint32_t id) +get_keyboard(struct wl_client *client, struct wl_resource *resource, uint32_t id) { - keyboard_bind(&seat.keyboard, client, - wl_resource_get_version(resource), id); + keyboard_bind(&seat.keyboard, client, wl_resource_get_version(resource), id); } static void -get_touch(struct wl_client *client, struct wl_resource *resource, - uint32_t id) +get_touch(struct wl_client *client, struct wl_resource *resource, uint32_t id) { /* XXX: Implement */ } static struct wl_seat_interface seat_implementation = { - .get_pointer = &get_pointer, - .get_keyboard = &get_keyboard, - .get_touch = &get_touch + .get_pointer = get_pointer, + .get_keyboard = get_keyboard, + .get_touch = get_touch, }; static void -bind_seat(struct wl_client *client, void *data, uint32_t version, - uint32_t id) +bind_seat(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wl_resource *resource; @@ -209,8 +198,7 @@ bind_seat(struct wl_client *client, void *data, uint32_t version, version = 4; resource = wl_resource_create(client, &wl_seat_interface, version, id); - wl_resource_set_implementation(resource, &seat_implementation, NULL, - &remove_resource); + wl_resource_set_implementation(resource, &seat_implementation, NULL, &remove_resource); wl_list_insert(&seat.resources, wl_resource_get_link(resource)); if (version >= 2) @@ -222,13 +210,14 @@ bind_seat(struct wl_client *client, void *data, uint32_t version, static void update_capabilities(uint32_t capabilities) { - if (~seat.capabilities & capabilities) { - struct wl_resource *resource; + struct wl_resource *resource; - seat.capabilities |= capabilities; - wl_list_for_each (resource, &seat.resources, link) - wl_seat_send_capabilities(resource, seat.capabilities); - } + if (!(~seat.capabilities & capabilities)) + return; + + seat.capabilities |= capabilities; + wl_list_for_each(resource, &seat.resources, link) + wl_seat_send_capabilities(resource, seat.capabilities); } #ifdef ENABLE_LIBINPUT @@ -245,8 +234,8 @@ close_restricted(int fd, void *user_data) } const struct libinput_interface libinput_interface = { - .open_restricted = &open_restricted, - .close_restricted = &close_restricted, + .open_restricted = open_restricted, + .close_restricted = close_restricted, }; static uint32_t @@ -259,25 +248,23 @@ device_capabilities(struct libinput_device *device) if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)) capabilities |= WL_SEAT_CAPABILITY_POINTER; /* TODO: Add touch device support - if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH)) - capabilities |= WL_SEAT_CAPABILITY_TOUCH; - */ + * if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH)) + * capabilities |= WL_SEAT_CAPABILITY_TOUCH; + */ return capabilities; } static void -handle_libinput_axis_event(struct libinput_event_pointer *event, - enum libinput_pointer_axis axis) +handle_libinput_axis_event(struct libinput_event_pointer *event, enum libinput_pointer_axis axis) { + double amount; + if (!libinput_event_pointer_has_axis(event, axis)) return; - double amount; - amount = libinput_event_pointer_get_axis_value(event, axis); - handle_axis(libinput_event_pointer_get_time(event), axis, - wl_fixed_from_double(amount)); + handle_axis(libinput_event_pointer_get_time(event), axis, wl_fixed_from_double(amount)); } static int @@ -315,8 +302,7 @@ handle_libinput_data(int fd, uint32_t mask, void *data) event = libinput_event_get_pointer_event(generic_event); dx = wl_fixed_from_double(libinput_event_pointer_get_dx(event)); dy = wl_fixed_from_double(libinput_event_pointer_get_dy(event)); - handle_relative_motion(libinput_event_pointer_get_time(event), - dx, dy); + handle_relative_motion(libinput_event_pointer_get_time(event), dx, dy); break; } case LIBINPUT_EVENT_POINTER_BUTTON: { @@ -334,7 +320,6 @@ handle_libinput_data(int fd, uint32_t mask, void *data) event = libinput_event_get_pointer_event(generic_event); handle_libinput_axis_event(event, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); handle_libinput_axis_event(event, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); - break; } default: @@ -355,8 +340,7 @@ initialize_libinput(const char *seat_name) goto error0; } - seat.libinput = libinput_udev_create_context(&libinput_interface, NULL, - seat.udev); + seat.libinput = libinput_udev_create_context(&libinput_interface, NULL, seat.udev); if (!seat.libinput) { ERROR("Could not create libinput context\n"); @@ -368,8 +352,9 @@ initialize_libinput(const char *seat_name) goto error2; } - seat.libinput_source = wl_event_loop_add_fd(swc.event_loop, libinput_get_fd(seat.libinput), WL_EVENT_READABLE, - &handle_libinput_data, NULL); + seat.libinput_source = wl_event_loop_add_fd + (swc.event_loop, libinput_get_fd(seat.libinput), WL_EVENT_READABLE, + &handle_libinput_data, NULL); if (!seat.libinput_source) { ERROR("Could not create event source for libinput\n"); @@ -398,10 +383,10 @@ finalize_libinput(void) } #else const static struct evdev_device_handler evdev_handler = { - .key = &handle_key, - .button = &handle_button, - .axis = &handle_axis, - .relative_motion = &handle_relative_motion, + .key = handle_key, + .button = handle_button, + .axis = handle_axis, + .relative_motion = handle_relative_motion, }; static void @@ -422,7 +407,6 @@ static int select_device(const struct dirent *entry) { unsigned num; - return sscanf(entry->d_name, "event%u", &num) == 1; } @@ -430,9 +414,8 @@ static bool add_devices(void) { struct dirent **devices; - int num_devices; + int i, num_devices; char path[64]; - unsigned index; num_devices = scandir("/dev/input", &devices, &select_device, &alphasort); @@ -441,9 +424,9 @@ add_devices(void) return false; } - for (index = 0; index < num_devices; ++index) { - snprintf(path, sizeof path, "/dev/input/%s", devices[index]->d_name); - free(devices[index]); + for (i = 0; i < num_devices; ++i) { + snprintf(path, sizeof path, "/dev/input/%s", devices[i]->d_name); + free(devices[i]); add_device(path); } @@ -461,8 +444,7 @@ seat_initialize(const char *seat_name) goto error0; } - seat.global = wl_global_create(swc.display, &wl_seat_interface, 4, - NULL, &bind_seat); + seat.global = wl_global_create(swc.display, &wl_seat_interface, 4, NULL, &bind_seat); if (!seat.global) goto error1; diff --git a/libswc/shell.c b/libswc/shell.c @@ -27,33 +27,28 @@ #include <wayland-server.h> -static struct - { +static struct { struct wl_global *global; } shell; static void -get_shell_surface(struct wl_client *client, - struct wl_resource *resource, uint32_t id, - struct wl_resource *surface_resource) +get_shell_surface(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource) { struct surface *surface = wl_resource_get_user_data(surface_resource); struct shell_surface *shell_surface; - shell_surface = shell_surface_new(client, wl_resource_get_version(resource), - id, surface); + shell_surface = shell_surface_new(client, wl_resource_get_version(resource), id, surface); if (!shell_surface) wl_resource_post_no_memory(resource); } static const struct wl_shell_interface shell_implementation = { - &get_shell_surface + .get_shell_surface = get_shell_surface, }; static void -bind_shell(struct wl_client *client, void *data, - uint32_t version, uint32_t id) +bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wl_resource *resource; @@ -67,9 +62,7 @@ bind_shell(struct wl_client *client, void *data, bool shell_initialize(void) { - shell.global = wl_global_create(swc.display, &wl_shell_interface, 1, - NULL, &bind_shell); - + shell.global = wl_global_create(swc.display, &wl_shell_interface, 1, NULL, &bind_shell); return shell.global; } diff --git a/libswc/shell_surface.c b/libswc/shell_surface.c @@ -48,9 +48,8 @@ configure(struct window *window, uint32_t width, uint32_t height) { struct shell_surface *shell_surface = wl_container_of(window, shell_surface, window); - wl_shell_surface_send_configure(shell_surface->resource, - WL_SHELL_SURFACE_RESIZE_NONE, - width, height); + wl_shell_surface_send_configure(shell_surface->resource, WL_SHELL_SURFACE_RESIZE_NONE, width, height); + /* wl_shell does not support acknowledging configures. */ window->configure.acknowledged = true; } @@ -68,19 +67,17 @@ close(struct window *window) } static const struct window_impl window_impl = { - .configure = &configure, - .close = &close, + .configure = configure, + .close = close, }; static void -pong(struct wl_client *client, struct wl_resource *resource, - uint32_t serial) +pong(struct wl_client *client, struct wl_resource *resource, uint32_t serial) { } static void -move(struct wl_client *client, struct wl_resource *resource, - struct wl_resource *seat_resource, uint32_t serial) +move(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { struct shell_surface *shell_surface = wl_resource_get_user_data(resource); struct button *button; @@ -93,8 +90,7 @@ move(struct wl_client *client, struct wl_resource *resource, static void resize(struct wl_client *client, struct wl_resource *resource, - struct wl_resource *seat_resource, uint32_t serial, - uint32_t edges) + struct wl_resource *seat_resource, uint32_t serial, uint32_t edges) { struct shell_surface *shell_surface = wl_resource_get_user_data(resource); struct button *button; @@ -106,8 +102,7 @@ resize(struct wl_client *client, struct wl_resource *resource, } static void -set_toplevel(struct wl_client *client, - struct wl_resource *resource) +set_toplevel(struct wl_client *client, struct wl_resource *resource) { struct shell_surface *shell_surface = wl_resource_get_user_data(resource); @@ -116,10 +111,8 @@ set_toplevel(struct wl_client *client, } static void -set_transient(struct wl_client *client, - struct wl_resource *resource, - struct wl_resource *parent_resource, - int32_t x, int32_t y, uint32_t flags) +set_transient(struct wl_client *client, struct wl_resource *resource, + struct wl_resource *parent_resource, int32_t x, int32_t y, uint32_t flags) { struct shell_surface *shell_surface = wl_resource_get_user_data(resource); struct surface *parent_surface = wl_resource_get_user_data(parent_resource); @@ -133,19 +126,14 @@ set_transient(struct wl_client *client, } static void -set_fullscreen(struct wl_client *client, - struct wl_resource *resource, - uint32_t method, uint32_t framerate, - struct wl_resource *output_resource) +set_fullscreen(struct wl_client *client, struct wl_resource *resource, + uint32_t method, uint32_t framerate, struct wl_resource *output_resource) { struct shell_surface *shell_surface = wl_resource_get_user_data(resource); - struct output *output = output_resource - ? wl_resource_get_user_data(output_resource) - : NULL; + struct output *output = output_resource ? wl_resource_get_user_data(output_resource) : NULL; struct screen *screen; - screen = output ? output->screen - : wl_container_of(swc.screens.next, screen, link); + screen = output ? output->screen : wl_container_of(swc.screens.next, screen, link); /* TODO: Handle fullscreen windows. */ @@ -156,8 +144,7 @@ set_fullscreen(struct wl_client *client, static void set_popup(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, - struct wl_resource *parent_resource, - int32_t x, int32_t y, uint32_t flags) + struct wl_resource *parent_resource, int32_t x, int32_t y, uint32_t flags) { struct shell_surface *shell_surface = wl_resource_get_user_data(resource); struct surface *parent_surface = wl_resource_get_user_data(parent_resource); @@ -168,15 +155,11 @@ set_popup(struct wl_client *client, struct wl_resource *resource, window_unmanage(&shell_surface->window); window_set_parent(&shell_surface->window, parent_view->window); - view_move(&shell_surface->window.view->base, - parent_view->base.geometry.x + x, - parent_view->base.geometry.y + y); + view_move(&shell_surface->window.view->base, parent_view->base.geometry.x + x, parent_view->base.geometry.y + y); } static void -set_maximized(struct wl_client *client, - struct wl_resource *resource, - struct wl_resource *output_resource) +set_maximized(struct wl_client *client, struct wl_resource *resource, struct wl_resource *output_resource) { struct shell_surface *shell_surface = wl_resource_get_user_data(resource); @@ -187,41 +170,36 @@ set_maximized(struct wl_client *client, } static void -set_title(struct wl_client *client, struct wl_resource *resource, - const char *title) +set_title(struct wl_client *client, struct wl_resource *resource, const char *title) { struct shell_surface *shell_surface = wl_resource_get_user_data(resource); - window_set_title(&shell_surface->window, title, -1); } static void -set_class(struct wl_client *client, struct wl_resource *resource, - const char *class) +set_class(struct wl_client *client, struct wl_resource *resource, const char *class) { struct shell_surface *shell_surface = wl_resource_get_user_data(resource); - window_set_app_id(&shell_surface->window, class); } static const struct wl_shell_surface_interface shell_surface_implementation = { - .pong = &pong, - .move = &move, - .resize = &resize, - .set_toplevel = &set_toplevel, - .set_transient = &set_transient, - .set_fullscreen = &set_fullscreen, - .set_popup = &set_popup, - .set_maximized = &set_maximized, - .set_title = &set_title, - .set_class = &set_class + .pong = pong, + .move = move, + .resize = resize, + .set_toplevel = set_toplevel, + .set_transient = set_transient, + .set_fullscreen = set_fullscreen, + .set_popup = set_popup, + .set_maximized = set_maximized, + .set_title = set_title, + .set_class = set_class, }; static void handle_surface_destroy(struct wl_listener *listener, void *data) { struct shell_surface *shell_surface = wl_container_of(listener, shell_surface, surface_destroy_listener); - wl_resource_destroy(shell_surface->resource); } @@ -235,9 +213,7 @@ destroy_shell_surface(struct wl_resource *resource) } struct shell_surface * -shell_surface_new(struct wl_client *client, - uint32_t version, uint32_t id, - struct surface *surface) +shell_surface_new(struct wl_client *client, uint32_t version, uint32_t id, struct surface *surface) { struct shell_surface *shell_surface; @@ -251,14 +227,10 @@ shell_surface_new(struct wl_client *client, if (!shell_surface->resource) goto error1; - wl_resource_set_implementation(shell_surface->resource, - &shell_surface_implementation, - shell_surface, &destroy_shell_surface); - + wl_resource_set_implementation(shell_surface->resource, &shell_surface_implementation, shell_surface, &destroy_shell_surface); window_initialize(&shell_surface->window, &window_impl, surface); shell_surface->surface_destroy_listener.notify = &handle_surface_destroy; - wl_resource_add_destroy_listener(surface->resource, - &shell_surface->surface_destroy_listener); + wl_resource_add_destroy_listener(surface->resource, &shell_surface->surface_destroy_listener); return shell_surface; diff --git a/libswc/shell_surface.h b/libswc/shell_surface.h @@ -29,8 +29,6 @@ struct surface; struct wl_client; -struct shell_surface *shell_surface_new(struct wl_client *client, - uint32_t version, uint32_t id, - struct surface *surface); +struct shell_surface *shell_surface_new(struct wl_client *client, uint32_t version, uint32_t id, struct surface *surface); #endif diff --git a/libswc/shm.c b/libswc/shm.c @@ -39,8 +39,7 @@ struct swc_shm swc_shm; -static struct - { +static struct { struct wl_global *global; } shm; @@ -70,7 +69,6 @@ static void destroy_pool_resource(struct wl_resource *resource) { struct pool *pool = wl_resource_get_user_data(resource); - unref_pool(pool); } @@ -78,7 +76,6 @@ static void handle_buffer_destroy(struct wld_destructor *destructor) { struct pool_reference *reference = wl_container_of(destructor, reference, destructor); - unref_pool(reference->pool); } @@ -96,10 +93,8 @@ format_shm_to_wld(uint32_t format) } static void -create_buffer(struct wl_client *client, - struct wl_resource *resource, uint32_t id, - int32_t offset, int32_t width, int32_t height, - int32_t stride, uint32_t format) +create_buffer(struct wl_client *client, struct wl_resource *resource, + uint32_t id, int32_t offset, int32_t width, int32_t height, int32_t stride, uint32_t format) { struct pool *pool = wl_resource_get_user_data(resource); struct pool_reference *reference; @@ -108,15 +103,12 @@ create_buffer(struct wl_client *client, union wld_object object; if (offset > pool->size || offset < 0) { - wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_STRIDE, - "offset is too big or negative"); + wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_STRIDE, "offset is too big or negative"); return; } object.ptr = (void *)((uintptr_t)pool->data + offset); - buffer = wld_import_buffer(swc.shm->context, WLD_OBJECT_DATA, object, - width, height, format_shm_to_wld(format), - stride); + buffer = wld_import_buffer(swc.shm->context, WLD_OBJECT_DATA, object, width, height, format_shm_to_wld(format), stride); if (!buffer) goto error0; @@ -151,8 +143,7 @@ destroy(struct wl_client *client, struct wl_resource *resource) } static void -resize(struct wl_client *client, struct wl_resource *resource, - int32_t size) +resize(struct wl_client *client, struct wl_resource *resource, int32_t size) { struct pool *pool = wl_resource_get_user_data(resource); void *data; @@ -160,8 +151,7 @@ resize(struct wl_client *client, struct wl_resource *resource, data = mremap(pool->data, pool->size, size, MREMAP_MAYMOVE); if (data == MAP_FAILED) { - wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_FD, - "mremap failed: %s", strerror(errno)); + wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_FD, "mremap failed: %s", strerror(errno)); return; } @@ -170,15 +160,13 @@ resize(struct wl_client *client, struct wl_resource *resource, } static struct wl_shm_pool_interface shm_pool_implementation = { - .create_buffer = &create_buffer, - .destroy = &destroy, - .resize = &resize + .create_buffer = create_buffer, + .destroy = destroy, + .resize = resize, }; static void -create_pool(struct wl_client *client, - struct wl_resource *resource, uint32_t id, - int32_t fd, int32_t size) +create_pool(struct wl_client *client, struct wl_resource *resource, uint32_t id, int32_t fd, int32_t size) { struct pool *pool; @@ -187,21 +175,18 @@ create_pool(struct wl_client *client, return; } - pool->resource = wl_resource_create(client, &wl_shm_pool_interface, - wl_resource_get_version(resource), id); + pool->resource = wl_resource_create(client, &wl_shm_pool_interface, wl_resource_get_version(resource), id); if (!pool->resource) { wl_resource_post_no_memory(resource); goto error0; } - wl_resource_set_implementation(pool->resource, &shm_pool_implementation, - pool, &destroy_pool_resource); + wl_resource_set_implementation(pool->resource, &shm_pool_implementation, pool, &destroy_pool_resource); pool->data = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); if (pool->data == MAP_FAILED) { - wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_FD, - "mmap failed: %s", strerror(errno)); + wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_FD, "mmap failed: %s", strerror(errno)); goto error1; } @@ -221,8 +206,7 @@ static struct wl_shm_interface shm_implementation = { }; static void -bind_shm(struct wl_client *client, void *data, uint32_t version, - uint32_t id) +bind_shm(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wl_resource *resource; @@ -245,8 +229,7 @@ shm_initialize(void) if (!(swc.shm->renderer = wld_create_renderer(swc.shm->context))) goto error1; - shm.global = wl_global_create(swc.display, &wl_shm_interface, 1, - NULL, &bind_shm); + shm.global = wl_global_create(swc.display, &wl_shm_interface, 1, NULL, &bind_shm); if (!shm.global) goto error2; diff --git a/libswc/shm.h b/libswc/shm.h @@ -32,7 +32,6 @@ struct swc_shm { }; bool shm_initialize(void); - void shm_finalize(void); #endif diff --git a/libswc/subcompositor.c b/libswc/subcompositor.c @@ -29,11 +29,8 @@ static struct wl_global *global; static void -get_subsurface(struct wl_client *client, - struct wl_resource *resource, - uint32_t id, - struct wl_resource *surface_resource, - struct wl_resource *parent_resource) +get_subsurface(struct wl_client *client, struct wl_resource *resource, + uint32_t id, struct wl_resource *surface_resource, struct wl_resource *parent_resource) { struct subsurface *subsurface; @@ -46,29 +43,25 @@ get_subsurface(struct wl_client *client, } static struct wl_subcompositor_interface subcompositor_implementation = { - .get_subsurface = &get_subsurface, + .get_subsurface = get_subsurface, }; static void -bind_subcompositor(struct wl_client *client, void *data, - uint32_t version, uint32_t id) +bind_subcompositor(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wl_resource *resource; if (version > 1) version = 1; - resource = wl_resource_create(client, &wl_subcompositor_interface, - version, id); - wl_resource_set_implementation(resource, &subcompositor_implementation, - NULL, NULL); + resource = wl_resource_create(client, &wl_subcompositor_interface, version, id); + wl_resource_set_implementation(resource, &subcompositor_implementation, NULL, NULL); } bool -subcompositor_initialize() +subcompositor_initialize(void) { - global = wl_global_create(swc.display, &wl_subcompositor_interface, 1, - NULL, &bind_subcompositor); + global = wl_global_create(swc.display, &wl_subcompositor_interface, 1, NULL, &bind_subcompositor); if (!global) return false; @@ -77,7 +70,7 @@ subcompositor_initialize() } void -subcompositor_finalize() +subcompositor_finalize(void) { wl_global_destroy(global); } diff --git a/libswc/subcompositor.h b/libswc/subcompositor.h @@ -24,8 +24,7 @@ #ifndef SWC_SUBCOMPOSITOR_H #define SWC_SUBCOMPOSITOR_H -bool subcompositor_initialize(); - -void subcompositor_finalize(); +bool subcompositor_initialize(void); +void subcompositor_finalize(void); #endif diff --git a/libswc/subsurface.c b/libswc/subsurface.c @@ -33,25 +33,19 @@ destroy(struct wl_client *client, struct wl_resource *resource) } static void -set_position(struct wl_client *client, - struct wl_resource *resource, - int32_t x, int32_t y) +set_position(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y) { /* TODO: Implement. */ } static void -place_above(struct wl_client *client, - struct wl_resource *resource, - struct wl_resource *sibling_resource) +place_above(struct wl_client *client, struct wl_resource *resource, struct wl_resource *sibling_resource) { /* TODO: Implement. */ } static void -place_below(struct wl_client *client, - struct wl_resource *resource, - struct wl_resource *sibling_resource) +place_below(struct wl_client *client, struct wl_resource *resource, struct wl_resource *sibling_resource) { /* TODO: Implement. */ } @@ -69,40 +63,35 @@ set_desync(struct wl_client *client, struct wl_resource *resource) } static struct wl_subsurface_interface subsurface_implementation = { - .destroy = &destroy, - .set_position = &set_position, - .place_above = &place_above, - .place_below = &place_below, - .set_sync = &set_sync, - .set_desync = &set_desync, + .destroy = destroy, + .set_position = set_position, + .place_above = place_above, + .place_below = place_below, + .set_sync = set_sync, + .set_desync = set_desync, }; static void subsurface_destroy(struct wl_resource *resource) { struct subsurface *subsurface = wl_resource_get_user_data(resource); - free(subsurface); } struct subsurface * -subsurface_new(struct wl_client *client, - uint32_t version, uint32_t id) +subsurface_new(struct wl_client *client, uint32_t version, uint32_t id) { struct subsurface *subsurface; if (!(subsurface = malloc(sizeof *subsurface))) goto error0; - subsurface->resource = wl_resource_create(client, &wl_subsurface_interface, - version, id); + subsurface->resource = wl_resource_create(client, &wl_subsurface_interface, version, id); if (!subsurface->resource) goto error1; - wl_resource_set_implementation(subsurface->resource, - &subsurface_implementation, - subsurface, &subsurface_destroy); + wl_resource_set_implementation(subsurface->resource, &subsurface_implementation, subsurface, &subsurface_destroy); return subsurface; diff --git a/libswc/subsurface.h b/libswc/subsurface.h @@ -32,7 +32,6 @@ struct subsurface { struct wl_resource *resource; }; -struct subsurface *subsurface_new(struct wl_client *client, - uint32_t version, uint32_t id); +struct subsurface *subsurface_new(struct wl_client *client, uint32_t version, uint32_t id); #endif diff --git a/libswc/surface.c b/libswc/surface.c @@ -65,10 +65,8 @@ state_finalize(struct surface_state *state) { struct wl_resource *resource, *tmp; - if (state->buffer) { - /* Remove any buffer listeners */ + if (state->buffer) wl_list_remove(&state->buffer_destroy_listener.link); - } pixman_region32_fini(&state->damage); pixman_region32_fini(&state->opaque); @@ -84,22 +82,15 @@ state_finalize(struct surface_state *state) * to manage the destroy listeners we have for the new and old buffer. */ static void -state_set_buffer(struct surface_state *state, - struct wl_resource *resource) +state_set_buffer(struct surface_state *state, struct wl_resource *resource) { struct wld_buffer *buffer = resource ? wayland_buffer_get(resource) : NULL; - if (state->buffer) { - /* No longer need to worry about the old buffer being destroyed. */ + if (state->buffer) wl_list_remove(&state->buffer_destroy_listener.link); - } - if (buffer) { - /* Need to watch the new buffer for destruction so we can remove it - * from state. */ - wl_resource_add_destroy_listener(resource, - &state->buffer_destroy_listener); - } + if (buffer) + wl_resource_add_destroy_listener(resource, &state->buffer_destroy_listener); state->buffer = buffer; state->buffer_resource = resource; @@ -111,8 +102,7 @@ handle_frame(struct view_handler *handler, uint32_t time) struct surface *surface = wl_container_of(handler, surface, view_handler); struct wl_resource *resource, *tmp; - wl_list_for_each_safe (resource, tmp, - &surface->state.frame_callbacks, link) { + wl_list_for_each_safe (resource, tmp, &surface->state.frame_callbacks, link) { wl_callback_send_done(resource, time); wl_resource_destroy(resource); } @@ -121,8 +111,7 @@ handle_frame(struct view_handler *handler, uint32_t time) } static void -handle_screens(struct view_handler *handler, - uint32_t entered, uint32_t left) +handle_screens(struct view_handler *handler, uint32_t entered, uint32_t left) { struct surface *surface = wl_container_of(handler, surface, view_handler); struct screen *screen; @@ -150,8 +139,8 @@ handle_screens(struct view_handler *handler, } static const struct view_handler_impl view_handler_impl = { - .frame = &handle_frame, - .screens = &handle_screens, + .frame = handle_frame, + .screens = handle_screens, }; static void @@ -174,39 +163,28 @@ attach(struct wl_client *client, struct wl_resource *resource, } static void -damage(struct wl_client *client, struct wl_resource *resource, - int32_t x, int32_t y, int32_t width, int32_t height) +damage(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) { struct surface *surface = wl_resource_get_user_data(resource); surface->pending.commit |= SURFACE_COMMIT_DAMAGE; - - pixman_region32_union_rect(&surface->pending.state.damage, - &surface->pending.state.damage, - x, y, width, height); + pixman_region32_union_rect(&surface->pending.state.damage, &surface->pending.state.damage, x, y, width, height); } static void -frame(struct wl_client *client, struct wl_resource *resource, - uint32_t id) +frame(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct surface *surface = wl_resource_get_user_data(resource); struct wl_resource *callback_resource; surface->pending.commit |= SURFACE_COMMIT_FRAME; - - callback_resource = wl_resource_create(client, &wl_callback_interface, - 1, id); - wl_resource_set_implementation(callback_resource, NULL, NULL, - &remove_resource); - wl_list_insert(surface->pending.state.frame_callbacks.prev, - wl_resource_get_link(callback_resource)); + callback_resource = wl_resource_create(client, &wl_callback_interface, 1, id); + wl_resource_set_implementation(callback_resource, NULL, NULL, &remove_resource); + wl_list_insert(surface->pending.state.frame_callbacks.prev, wl_resource_get_link(callback_resource)); } static void -set_opaque_region(struct wl_client *client, - struct wl_resource *resource, - struct wl_resource *region_resource) +set_opaque_region(struct wl_client *client, struct wl_resource *resource, struct wl_resource *region_resource) { struct surface *surface = wl_resource_get_user_data(resource); @@ -214,16 +192,14 @@ set_opaque_region(struct wl_client *client, if (region_resource) { struct region *region = wl_resource_get_user_data(region_resource); - pixman_region32_copy(&surface->pending.state.opaque, &region->region); - } else + } else { pixman_region32_clear(&surface->pending.state.opaque); + } } static void -set_input_region(struct wl_client *client, - struct wl_resource *resource, - struct wl_resource *region_resource) +set_input_region(struct wl_client *client, struct wl_resource *resource, struct wl_resource *region_resource) { struct surface *surface = wl_resource_get_user_data(resource); @@ -231,19 +207,16 @@ set_input_region(struct wl_client *client, if (region_resource) { struct region *region = wl_resource_get_user_data(region_resource); - pixman_region32_copy(&surface->pending.state.input, &region->region); - } else + } else { pixman_region32_reset(&surface->pending.state.input, &infinite_extents); + } } static inline void -trim_region(pixman_region32_t *region, - struct wld_buffer *buffer) +trim_region(pixman_region32_t *region, struct wld_buffer *buffer) { - pixman_region32_intersect_rect(region, region, 0, 0, - buffer ? buffer->width : 0, - buffer ? buffer->height : 0); + pixman_region32_intersect_rect(region, region, 0, 0, buffer ? buffer->width : 0, buffer ? buffer->height : 0); } static void @@ -254,40 +227,31 @@ commit(struct wl_client *client, struct wl_resource *resource) /* Attach */ if (surface->pending.commit & SURFACE_COMMIT_ATTACH) { - if (surface->state.buffer - && surface->state.buffer != surface->pending.state.buffer) { + if (surface->state.buffer && surface->state.buffer != surface->pending.state.buffer) wl_buffer_send_release(surface->state.buffer_resource); - } - state_set_buffer(&surface->state, - surface->pending.state.buffer_resource); + state_set_buffer(&surface->state, surface->pending.state.buffer_resource); } buffer = surface->state.buffer; /* Damage */ if (surface->pending.commit & SURFACE_COMMIT_DAMAGE) { - pixman_region32_union(&surface->state.damage, &surface->state.damage, - &surface->pending.state.damage); + pixman_region32_union(&surface->state.damage, &surface->state.damage, &surface->pending.state.damage); pixman_region32_clear(&surface->pending.state.damage); } /* Opaque */ - if (surface->pending.commit & SURFACE_COMMIT_OPAQUE) { - pixman_region32_copy(&surface->state.opaque, - &surface->pending.state.opaque); - } + if (surface->pending.commit & SURFACE_COMMIT_OPAQUE) + pixman_region32_copy(&surface->state.opaque, &surface->pending.state.opaque); /* Input */ - if (surface->pending.commit & SURFACE_COMMIT_INPUT) { - pixman_region32_copy(&surface->state.input, - &surface->pending.state.input); - } + if (surface->pending.commit & SURFACE_COMMIT_INPUT) + pixman_region32_copy(&surface->state.input, &surface->pending.state.input); /* Frame */ if (surface->pending.commit & SURFACE_COMMIT_FRAME) { - wl_list_insert_list(&surface->state.frame_callbacks, - &surface->pending.state.frame_callbacks); + wl_list_insert_list(&surface->state.frame_callbacks, &surface->pending.state.frame_callbacks); wl_list_init(&surface->pending.state.frame_callbacks); } @@ -304,29 +268,27 @@ commit(struct wl_client *client, struct wl_resource *resource) } void -set_buffer_transform(struct wl_client *client, - struct wl_resource *surface, int32_t transform) +set_buffer_transform(struct wl_client *client, struct wl_resource *surface, int32_t transform) { /* TODO: Implement */ } void -set_buffer_scale(struct wl_client *client, struct wl_resource *surface, - int32_t scale) +set_buffer_scale(struct wl_client *client, struct wl_resource *surface, int32_t scale) { /* TODO: Implement */ } static struct wl_surface_interface surface_implementation = { - .destroy = &destroy, - .attach = &attach, - .damage = &damage, - .frame = &frame, - .set_opaque_region = &set_opaque_region, - .set_input_region = &set_input_region, - .commit = &commit, - .set_buffer_transform = &set_buffer_transform, - .set_buffer_scale = &set_buffer_scale + .destroy = destroy, + .attach = attach, + .damage = damage, + .frame = frame, + .set_opaque_region = set_opaque_region, + .set_input_region = set_input_region, + .commit = commit, + .set_buffer_transform = set_buffer_transform, + .set_buffer_scale = set_buffer_scale, }; static void @@ -351,8 +313,7 @@ surface_destroy(struct wl_resource *resource) * @return The newly allocated surface. */ struct surface * -surface_new(struct wl_client *client, - uint32_t version, uint32_t id) +surface_new(struct wl_client *client, uint32_t version, uint32_t id) { struct surface *surface; @@ -370,10 +331,8 @@ surface_new(struct wl_client *client, state_initialize(&surface->pending.state); /* Add the surface to the client. */ - surface->resource = wl_resource_create(client, &wl_surface_interface, - version, id); - wl_resource_set_implementation(surface->resource, &surface_implementation, - surface, &surface_destroy); + surface->resource = wl_resource_create(client, &wl_surface_interface, version, id); + wl_resource_set_implementation(surface->resource, &surface_implementation, surface, &surface_destroy); return surface; } diff --git a/libswc/surface.h b/libswc/surface.h @@ -60,8 +60,7 @@ struct surface { struct surface_state state; - struct - { + struct { struct surface_state state; uint32_t commit; int32_t x, y; @@ -71,9 +70,7 @@ struct surface { struct view_handler view_handler; }; -struct surface *surface_new(struct wl_client *client, - uint32_t version, uint32_t id); - +struct surface *surface_new(struct wl_client *client, uint32_t version, uint32_t id); void surface_set_view(struct surface *surface, struct view *view); #endif diff --git a/libswc/swc.c b/libswc/swc.c @@ -41,7 +41,7 @@ #include "window.h" #include "xdg_shell.h" #ifdef ENABLE_XWAYLAND -#include "xserver.h" +# include "xserver.h" #endif extern struct swc_launch swc_launch; @@ -72,27 +72,20 @@ setup_compositor(void) { pixman_region32_t pointer_region; struct screen *screen; - struct swc_rectangle *geometry; - - wl_list_insert(&swc.seat->keyboard->handlers, - &swc.bindings->keyboard_handler->link); - wl_list_insert(&swc.seat->pointer->handlers, - &swc.bindings->pointer_handler->link); - wl_list_insert(&swc.seat->pointer->handlers, - &swc.compositor->pointer_handler->link); - wl_list_insert(&swc.seat->pointer->handlers, - &screens_pointer_handler.link); - wl_signal_add(&swc.seat->pointer->focus.event_signal, - &window_enter_listener); + struct swc_rectangle *geom; + + wl_list_insert(&swc.seat->keyboard->handlers, &swc.bindings->keyboard_handler->link); + wl_list_insert(&swc.seat->pointer->handlers, &swc.bindings->pointer_handler->link); + wl_list_insert(&swc.seat->pointer->handlers, &swc.compositor->pointer_handler->link); + wl_list_insert(&swc.seat->pointer->handlers, &screens_pointer_handler.link); + wl_signal_add(&swc.seat->pointer->focus.event_signal, &window_enter_listener); /* Calculate pointer region */ pixman_region32_init(&pointer_region); wl_list_for_each (screen, &swc.screens, link) { - geometry = &screen->base.geometry; - pixman_region32_union_rect(&pointer_region, &pointer_region, - geometry->x, geometry->y, - geometry->width, geometry->height); + geom = &screen->base.geometry; + pixman_region32_union_rect(&pointer_region, &pointer_region, geom->x, geom->y, geom->width, geom->height); } pointer_set_region(swc.seat->pointer, &pointer_region); @@ -113,14 +106,11 @@ swc_deactivate(void) send_event(&swc.event_signal, SWC_EVENT_DEACTIVATED, NULL); } -EXPORT -bool -swc_initialize(struct wl_display *display, - struct wl_event_loop *event_loop, - const struct swc_manager *manager) +EXPORT bool +swc_initialize(struct wl_display *display, struct wl_event_loop *event_loop, const struct swc_manager *manager) { swc.display = display; - swc.event_loop = event_loop ?: wl_display_get_event_loop(display); + swc.event_loop = event_loop ? event_loop : wl_display_get_event_loop(display); swc.manager = manager; const char *default_seat = "seat0"; wl_signal_init(&swc.event_signal); @@ -226,8 +216,7 @@ error0: return false; } -EXPORT -void +EXPORT void swc_finalize(void) { #ifdef ENABLE_XWAYLAND diff --git a/libswc/swc.h b/libswc/swc.h @@ -41,50 +41,48 @@ struct swc_rectangle { struct swc_screen_handler { /** - * Called when the screen is about to be destroyed. - * - * After this is called, the screen is no longer valid. - */ + * Called when the screen is about to be destroyed. + * + * After this is called, the screen is no longer valid. + */ void (*destroy)(void *data); /** - * Called when the total area of the screen has changed. - */ + * Called when the total area of the screen has changed. + */ void (*geometry_changed)(void *data); /** - * Called when the geometry of the screen available for laying out windows - * has changed. - * - * A window manager should respond by making sure all visible windows are - * within this area. - */ + * Called when the geometry of the screen available for laying out windows has + * changed. + * + * A window manager should respond by making sure all visible windows are + * within this area. + */ void (*usable_geometry_changed)(void *data); /** - * Called when the pointer enters the screen. - */ + * Called when the pointer enters the screen. + */ void (*entered)(void *data); }; struct swc_screen { /** - * The total area of the screen. - */ + * The total area of the screen. + */ struct swc_rectangle geometry; /** - * The area of the screen available for placing windows. - */ + * The area of the screen available for placing windows. + */ struct swc_rectangle usable_geometry; }; /** * Set the handler associated with this screen. */ -void swc_screen_set_handler(struct swc_screen *screen, - const struct swc_screen_handler *handler, - void *data); +void swc_screen_set_handler(struct swc_screen *screen, const struct swc_screen_handler *handler, void *data); /* }}} */ @@ -92,51 +90,51 @@ void swc_screen_set_handler(struct swc_screen *screen, struct swc_window_handler { /** - * Called when the window is about to be destroyed. - * - * After this is called, the window is no longer valid. - */ + * Called when the window is about to be destroyed. + * + * After this is called, the window is no longer valid. + */ void (*destroy)(void *data); /** - * Called when the window's title changes. - */ + * Called when the window's title changes. + */ void (*title_changed)(void *data); /** - * Called when the window's application identifier changes. - */ + * Called when the window's application identifier changes. + */ void (*app_id_changed)(void *data); /** - * Called when the window's parent changes. - * - * This can occur when the window becomes a transient for another window, or - * becomes a toplevel window. - */ + * Called when the window's parent changes. + * + * This can occur when the window becomes a transient for another window, or + * becomes a toplevel window. + */ void (*parent_changed)(void *data); /** - * Called when the pointer enters the window. - */ + * Called when the pointer enters the window. + */ void (*entered)(void *data); /** - * Called when the window wants to initiate an interactive move, but the - * window is not in stacked mode. - * - * The window manager may respond by changing the window's mode, after which - * the interactive move will be honored. - */ + * Called when the window wants to initiate an interactive move, but the + * window is not in stacked mode. + * + * The window manager may respond by changing the window's mode, after which + * the interactive move will be honored. + */ void (*move)(void *data); /** - * Called when the window wants to initiate an interactive resize, but the - * window is not in stacked mode. - * - * The window manager may respond by changing the window's mode, after which - * the interactive resize will be honored. - */ + * Called when the window wants to initiate an interactive resize, but the + * window is not in stacked mode. + * + * The window manager may respond by changing the window's mode, after which + * the interactive resize will be honored. + */ void (*resize)(void *data); }; @@ -150,9 +148,7 @@ struct swc_window { /** * Set the handler associated with this window. */ -void swc_window_set_handler(struct swc_window *window, - const struct swc_window_handler *handler, - void *data); +void swc_window_set_handler(struct swc_window *window, const struct swc_window_handler *handler, void *data); /** * Request that the specified window close. @@ -201,8 +197,7 @@ void swc_window_set_tiled(struct swc_window *window); /** * Sets the window to fullscreen mode. */ -void swc_window_set_fullscreen(struct swc_window *window, - struct swc_screen *screen); +void swc_window_set_fullscreen(struct swc_window *window, struct swc_screen *screen); /** * Set the window's position. @@ -218,8 +213,7 @@ void swc_window_set_position(struct swc_window *window, int32_t x, int32_t y); * The width and height refer to the dimension of the actual contents of the * window and should be adjusted for the border size. */ -void swc_window_set_size(struct swc_window *window, - uint32_t width, uint32_t height); +void swc_window_set_size(struct swc_window *window, uint32_t width, uint32_t height); /** * Set the window's size and position. @@ -227,8 +221,7 @@ void swc_window_set_size(struct swc_window *window, * This is a convenience function that is equivalent to calling * swc_window_set_size and then swc_window_set_position. */ -void swc_window_set_geometry(struct swc_window *window, - const struct swc_rectangle *geometry); +void swc_window_set_geometry(struct swc_window *window, const struct swc_rectangle *geometry); /** * Set the window's border color and width. @@ -236,8 +229,7 @@ void swc_window_set_geometry(struct swc_window *window, * NOTE: The window's geometry remains unchanged, and should be updated if a * fixed top-left corner of the border is desired. */ -void swc_window_set_border(struct swc_window *window, - uint32_t color, uint32_t width); +void swc_window_set_border(struct swc_window *window, uint32_t color, uint32_t width); /** * Begin an interactive move of the specified window. @@ -284,17 +276,14 @@ enum swc_binding_type { SWC_BINDING_BUTTON, }; -typedef void (*swc_binding_handler)(void *data, uint32_t time, - uint32_t value, uint32_t state); +typedef void (*swc_binding_handler)(void *data, uint32_t time, uint32_t value, uint32_t state); /** * Register a new input binding. * * Returns 0 on success, negative error code otherwise. */ -int swc_add_binding(enum swc_binding_type type, - uint32_t modifiers, uint32_t value, - swc_binding_handler handler, void *data); +int swc_add_binding(enum swc_binding_type type, uint32_t modifiers, uint32_t value, swc_binding_handler handler, void *data); /* }}} */ @@ -304,13 +293,13 @@ int swc_add_binding(enum swc_binding_type type, */ struct swc_manager { /** - * Called when a new screen is created. - */ + * Called when a new screen is created. + */ void (*new_screen)(struct swc_screen *screen); /** - * Called when a new window is created. - */ + * Called when a new window is created. + */ void (*new_window)(struct swc_window *window); }; @@ -318,9 +307,7 @@ struct swc_manager { * Initializes the compositor using the specified display, event_loop, and * manager. */ -bool swc_initialize(struct wl_display *display, - struct wl_event_loop *event_loop, - const struct swc_manager *manager); +bool swc_initialize(struct wl_display *display, struct wl_event_loop *event_loop, const struct swc_manager *manager); /** * Stops the compositor, releasing any used resources. diff --git a/libswc/util.c b/libswc/util.c @@ -26,7 +26,8 @@ #include <wayland-server.h> pixman_box32_t infinite_extents = { - .x1 = INT32_MIN, .y1 = INT32_MIN, .x2 = INT32_MAX, .y2 = INT32_MAX + .x1 = INT32_MIN, .y1 = INT32_MIN, + .x2 = INT32_MAX, .y2 = INT32_MAX, }; void diff --git a/libswc/util.h b/libswc/util.h @@ -44,9 +44,9 @@ #define MESSAGE_SOURCE #endif -#define MESSAGE(type, format, ...) \ - do { \ - MESSAGE_SOURCE \ +#define MESSAGE(type, format, ...) \ + do { \ + MESSAGE_SOURCE \ fprintf(stderr, type ": " format, ##__VA_ARGS__); \ } while (false) @@ -84,8 +84,7 @@ rectangle_contains_point(const struct swc_rectangle *rectangle, int32_t x, int32 } static inline bool -rectangle_overlap(const struct swc_rectangle *r1, - const struct swc_rectangle *r2) +rectangle_overlap(const struct swc_rectangle *r1, const struct swc_rectangle *r2) { return (MAX(r1->x + r1->width, r2->x + r2->width) - MIN(r1->x, r2->x) < r1->width + r2->width) @@ -94,8 +93,7 @@ rectangle_overlap(const struct swc_rectangle *r1, } static inline void -array_remove(struct wl_array *array, - void *item, size_t size) +array_remove(struct wl_array *array, void *item, size_t size) { size_t bytes = array->size - ((intptr_t)item + size - (intptr_t)array->data); if (bytes > 0) diff --git a/libswc/view.c b/libswc/view.c @@ -29,12 +29,12 @@ #include <wld/wld.h> -#define HANDLE(view, handler, method, ...) \ - do { \ - wl_list_for_each (handler, &view->handlers, link) { \ - if (handler->impl->method) \ +#define HANDLE(view, handler, method, ...) \ + do { \ + wl_list_for_each (handler, &view->handlers, link) { \ + if (handler->impl->method) \ handler->impl->method(handler, ##__VA_ARGS__); \ - } \ + } \ } while (0) void @@ -113,8 +113,7 @@ view_set_size(struct view *view, uint32_t width, uint32_t height) if (view->geometry.width == width && view->geometry.height == height) return false; - uint32_t old_width = view->geometry.width, - old_height = view->geometry.height; + uint32_t old_width = view->geometry.width, old_height = view->geometry.height; view->geometry.width = width; view->geometry.height = height; @@ -126,8 +125,7 @@ view_set_size(struct view *view, uint32_t width, uint32_t height) bool view_set_size_from_buffer(struct view *view, struct wld_buffer *buffer) { - return view_set_size(view, buffer ? buffer->width : 0, - buffer ? buffer->height : 0); + return view_set_size(view, buffer ? buffer->width : 0, buffer ? buffer->height : 0); } void @@ -136,8 +134,7 @@ view_set_screens(struct view *view, uint32_t screens) if (view->screens == screens) return; - uint32_t entered = screens & ~view->screens, - left = view->screens & ~screens; + uint32_t entered = screens & ~view->screens, left = view->screens & ~screens; struct view_handler *handler; view->screens = screens; @@ -162,6 +159,5 @@ void view_frame(struct view *view, uint32_t time) { struct view_handler *handler; - HANDLE(view, handler, frame, time); } diff --git a/libswc/view.h b/libswc/view.h @@ -72,11 +72,9 @@ struct view_handler_impl { /* Called after the view's position changes. */ void (*move)(struct view_handler *handler); /* Called after the view's size changes. */ - void (*resize)(struct view_handler *handler, - uint32_t old_width, uint32_t old_height); + void (*resize)(struct view_handler *handler, uint32_t old_width, uint32_t old_height); /* Called when the set of screens the view is visible on changes. */ - void (*screens)(struct view_handler *handler, - uint32_t left, uint32_t entered); + void (*screens)(struct view_handler *handler, uint32_t left, uint32_t entered); }; /** diff --git a/libswc/wayland_buffer.c b/libswc/wayland_buffer.c @@ -36,16 +36,14 @@ destroy(struct wl_client *client, struct wl_resource *resource) } static const struct wl_buffer_interface buffer_implementation = { - .destroy = &destroy + .destroy = destroy, }; struct wld_buffer * wayland_buffer_get(struct wl_resource *resource) { - if (wl_resource_instance_of(resource, &wl_buffer_interface, - &buffer_implementation)) { + if (wl_resource_instance_of(resource, &wl_buffer_interface, &buffer_implementation)) return wl_resource_get_user_data(resource); - } return NULL; } @@ -54,13 +52,11 @@ static void destroy_buffer(struct wl_resource *resource) { struct wld_buffer *buffer = wl_resource_get_user_data(resource); - wld_buffer_unreference(buffer); } struct wl_resource * -wayland_buffer_create_resource(struct wl_client *client, uint32_t version, uint32_t id, - struct wld_buffer *buffer) +wayland_buffer_create_resource(struct wl_client *client, uint32_t version, uint32_t id, struct wld_buffer *buffer) { struct wl_resource *resource; @@ -71,8 +67,7 @@ wayland_buffer_create_resource(struct wl_client *client, uint32_t version, uint3 return NULL; } - wl_resource_set_implementation(resource, &buffer_implementation, - buffer, &destroy_buffer); + wl_resource_set_implementation(resource, &buffer_implementation, buffer, &destroy_buffer); return resource; } diff --git a/libswc/wayland_buffer.h b/libswc/wayland_buffer.h @@ -30,8 +30,6 @@ struct wl_client; struct wl_resource; struct wld_buffer *wayland_buffer_get(struct wl_resource *resource); - -struct wl_resource *wayland_buffer_create_resource(struct wl_client *client, uint32_t version, uint32_t id, - struct wld_buffer *buffer); +struct wl_resource *wayland_buffer_create_resource(struct wl_client *client, uint32_t version, uint32_t id, struct wld_buffer *buffer); #endif diff --git a/libswc/window.c b/libswc/window.c @@ -56,29 +56,28 @@ handle_window_enter(struct wl_listener *listener, void *data) } struct wl_listener window_enter_listener = { - .notify = &handle_window_enter + .notify = handle_window_enter, }; static void -begin_interaction(struct window_pointer_interaction *interaction, - struct button *button) +begin_interaction(struct window_pointer_interaction *interaction, struct button *button) { if (button) { /* Store the serial of the button press so we are able to cancel the - * interaction if the window changes from stacked mode. */ + * interaction if the window changes from stacked mode. */ interaction->serial = button->press.serial; interaction->original_handler = button->handler; button->handler = &interaction->handler; - } else + } else { interaction->original_handler = NULL; + } interaction->active = true; wl_list_insert(&swc.seat->pointer->handlers, &interaction->handler.link); } static void -end_interaction(struct window_pointer_interaction *interaction, - struct button *button) +end_interaction(struct window_pointer_interaction *interaction, struct button *button) { if (!interaction->active) return; @@ -93,9 +92,7 @@ end_interaction(struct window_pointer_interaction *interaction, } } - interaction->original_handler->button(interaction->original_handler, - get_time(), button, - WL_POINTER_BUTTON_STATE_RELEASED); + interaction->original_handler->button(interaction->original_handler, get_time(), button, WL_POINTER_BUTTON_STATE_RELEASED); } remove: @@ -115,11 +112,8 @@ flush(struct window *window) } } -EXPORT -void -swc_window_set_handler(struct swc_window *base, - const struct swc_window_handler *handler, - void *data) +EXPORT void +swc_window_set_handler(struct swc_window *base, const struct swc_window_handler *handler, void *data) { struct window *window = INTERNAL(base); @@ -127,8 +121,7 @@ swc_window_set_handler(struct swc_window *base, window->handler_data = data; } -EXPORT -void +EXPORT void swc_window_close(struct swc_window *base) { struct window *window = INTERNAL(base); @@ -137,44 +130,39 @@ swc_window_close(struct swc_window *base) window->impl->close(window); } -EXPORT -void +EXPORT void swc_window_show(struct swc_window *window) { compositor_view_show(INTERNAL(window)->view); } -EXPORT -void +EXPORT void swc_window_hide(struct swc_window *window) { compositor_view_hide(INTERNAL(window)->view); } -EXPORT -void +EXPORT void swc_window_focus(struct swc_window *base) { struct window *window = INTERNAL(base); - struct compositor_view *new_focus = window ? window->view : NULL, - *old_focus = swc.seat->keyboard->focus.view; + struct compositor_view *new = window ? window->view : NULL, *old = swc.seat->keyboard->focus.view; - if (new_focus == old_focus) + if (new == old) return; /* Focus the new window before unfocusing the old one in case both are X11 - * windows so the xwl_window implementation can handle this transition - * correctly. */ + * windows so the xwl_window implementation can handle this transition + * correctly. */ if (window && window->impl->focus) window->impl->focus(window); - if (old_focus && old_focus->window && old_focus->window->impl->unfocus) - old_focus->window->impl->unfocus(old_focus->window); + if (old && old->window && old->window->impl->unfocus) + old->window->impl->unfocus(old->window); - keyboard_set_focus(swc.seat->keyboard, new_focus); + keyboard_set_focus(swc.seat->keyboard, new); } -EXPORT -void +EXPORT void swc_window_set_stacked(struct swc_window *base) { struct window *window = INTERNAL(base); @@ -188,8 +176,7 @@ swc_window_set_stacked(struct swc_window *base) window->mode = WINDOW_MODE_STACKED; } -EXPORT -void +EXPORT void swc_window_set_tiled(struct swc_window *base) { struct window *window = INTERNAL(base); @@ -201,10 +188,8 @@ swc_window_set_tiled(struct swc_window *base) window->mode = WINDOW_MODE_TILED; } -EXPORT -void -swc_window_set_fullscreen(struct swc_window *base, - struct swc_screen *screen) +EXPORT void +swc_window_set_fullscreen(struct swc_window *base, struct swc_screen *screen) { struct window *window = INTERNAL(base); @@ -215,8 +200,7 @@ swc_window_set_fullscreen(struct swc_window *base, window->mode = WINDOW_MODE_FULLSCREEN; } -EXPORT -void +EXPORT void swc_window_set_position(struct swc_window *base, int32_t x, int32_t y) { struct window *window = INTERNAL(base); @@ -236,19 +220,15 @@ swc_window_set_position(struct swc_window *base, int32_t x, int32_t y) flush(window); } -EXPORT -void -swc_window_set_size(struct swc_window *base, - uint32_t width, uint32_t height) +EXPORT void +swc_window_set_size(struct swc_window *base, uint32_t width, uint32_t height) { struct window *window = INTERNAL(base); - struct swc_rectangle *geometry = &window->view->base.geometry; + struct swc_rectangle *geom = &window->view->base.geometry; - if ((window->configure.pending - && width == window->configure.width - && height == window->configure.height) - || (!window->configure.pending - && width == geometry->width && height == geometry->height)) { + if ((window->configure.pending && width == window->configure.width && height == window->configure.height) + || (!window->configure.pending && width == geom->width && height == geom->height)) + { return; } @@ -261,19 +241,15 @@ swc_window_set_size(struct swc_window *base, } } -EXPORT -void -swc_window_set_geometry(struct swc_window *window, - const struct swc_rectangle *geometry) +EXPORT void +swc_window_set_geometry(struct swc_window *window, const struct swc_rectangle *geometry) { swc_window_set_size(window, geometry->width, geometry->height); swc_window_set_position(window, geometry->x, geometry->y); } -EXPORT -void -swc_window_set_border(struct swc_window *window, - uint32_t border_color, uint32_t border_width) +EXPORT void +swc_window_set_border(struct swc_window *window, uint32_t border_color, uint32_t border_width) { struct compositor_view *view = INTERNAL(window)->view; @@ -281,49 +257,43 @@ swc_window_set_border(struct swc_window *window, compositor_view_set_border_width(view, border_width); } -EXPORT -void +EXPORT void swc_window_begin_move(struct swc_window *window) { window_begin_move(INTERNAL(window), NULL); } -EXPORT -void +EXPORT void swc_window_end_move(struct swc_window *window) { end_interaction(&INTERNAL(window)->move.interaction, NULL); } -EXPORT -void +EXPORT void swc_window_begin_resize(struct swc_window *window, uint32_t edges) { window_begin_resize(INTERNAL(window), edges, NULL); } -EXPORT -void +EXPORT void swc_window_end_resize(struct swc_window *window) { end_interaction(&INTERNAL(window)->resize.interaction, NULL); } static bool -move_motion(struct pointer_handler *handler, uint32_t time, - wl_fixed_t fx, wl_fixed_t fy) +move_motion(struct pointer_handler *handler, uint32_t time, wl_fixed_t fx, wl_fixed_t fy) { struct window *window = wl_container_of(handler, window, move.interaction.handler); + int32_t x = wl_fixed_to_int(fx) + window->move.offset.x, + y = wl_fixed_to_int(fy) + window->move.offset.y; - view_move(&window->view->base, wl_fixed_to_int(fx) + window->move.offset.x, - wl_fixed_to_int(fy) + window->move.offset.y); - + view_move(&window->view->base, x, y); return true; } static bool -resize_motion(struct pointer_handler *handler, uint32_t time, - wl_fixed_t fx, wl_fixed_t fy) +resize_motion(struct pointer_handler *handler, uint32_t time, wl_fixed_t fx, wl_fixed_t fy) { struct window *window = wl_container_of(handler, window, resize.interaction.handler); const struct swc_rectangle *geometry = &window->view->base.geometry; @@ -345,15 +315,12 @@ resize_motion(struct pointer_handler *handler, uint32_t time, } static bool -handle_button(struct pointer_handler *handler, uint32_t time, - struct button *button, uint32_t state) +handle_button(struct pointer_handler *handler, uint32_t time, struct button *button, uint32_t state) { struct window_pointer_interaction *interaction = wl_container_of(handler, interaction, handler); - if (state != WL_POINTER_BUTTON_STATE_RELEASED - || !interaction->original_handler) { + if (state != WL_POINTER_BUTTON_STATE_RELEASED || !interaction->original_handler) return false; - } end_interaction(interaction, button); return true; @@ -370,13 +337,11 @@ handle_attach(struct view_handler *handler) } static void -handle_resize(struct view_handler *handler, - uint32_t old_width, uint32_t old_height) +handle_resize(struct view_handler *handler, uint32_t old_width, uint32_t old_height) { struct window *window = wl_container_of(handler, window, view_handler); - if (window->resize.interaction.active - && window->resize.edges & (SWC_WINDOW_EDGE_TOP | SWC_WINDOW_EDGE_LEFT)) { + if (window->resize.interaction.active && window->resize.edges & (SWC_WINDOW_EDGE_TOP | SWC_WINDOW_EDGE_LEFT)) { const struct swc_rectangle *geometry = &window->view->base.geometry; int32_t x = geometry->x, y = geometry->y; @@ -390,13 +355,12 @@ handle_resize(struct view_handler *handler, } static const struct view_handler_impl view_handler_impl = { - .attach = &handle_attach, - .resize = &handle_resize, + .attach = handle_attach, + .resize = handle_resize, }; bool -window_initialize(struct window *window, const struct window_impl *impl, - struct surface *surface) +window_initialize(struct window *window, const struct window_impl *impl, struct surface *surface) { DEBUG("Initializing window, %p\n", window); @@ -416,16 +380,16 @@ window_initialize(struct window *window, const struct window_impl *impl, window->move.pending = false; window->move.interaction.active = false; window->move.interaction.handler = (struct pointer_handler){ - .motion = &move_motion, - .button = &handle_button + .motion = move_motion, + .button = handle_button, }; window->configure.pending = false; window->configure.width = 0; window->configure.height = 0; window->resize.interaction.active = false; window->resize.interaction.handler = (struct pointer_handler){ - .motion = &resize_motion, - .button = &handle_button + .motion = resize_motion, + .button = handle_button, }; wl_list_insert(&window->view->base.handlers, &window->view_handler.link); @@ -518,16 +482,13 @@ window_begin_move(struct window *window, struct button *button) } void -window_begin_resize(struct window *window, uint32_t edges, - struct button *button) +window_begin_resize(struct window *window, uint32_t edges, struct button *button) { if (window->mode != WINDOW_MODE_STACKED && window->handler->resize) window->handler->resize(window->handler_data); - if (window->mode != WINDOW_MODE_STACKED - || window->resize.interaction.active) { + if (window->mode != WINDOW_MODE_STACKED || window->resize.interaction.active) return; - } struct swc_rectangle *geometry = &window->view->base.geometry; int32_t px = wl_fixed_to_int(swc.seat->pointer->x), @@ -536,17 +497,11 @@ window_begin_resize(struct window *window, uint32_t edges, begin_interaction(&window->resize.interaction, button); if (!edges) { - edges |= (px < geometry->x + geometry->width / 2) - ? SWC_WINDOW_EDGE_LEFT - : SWC_WINDOW_EDGE_RIGHT; - edges |= (py < geometry->y + geometry->height / 2) - ? SWC_WINDOW_EDGE_TOP - : SWC_WINDOW_EDGE_BOTTOM; + edges |= (px < geometry->x + geometry->width / 2) ? SWC_WINDOW_EDGE_LEFT : SWC_WINDOW_EDGE_RIGHT; + edges |= (py < geometry->y + geometry->height / 2) ? SWC_WINDOW_EDGE_TOP : SWC_WINDOW_EDGE_BOTTOM; } - window->resize.offset.x = geometry->x - px - + ((edges & SWC_WINDOW_EDGE_RIGHT) ? geometry->width : 0); - window->resize.offset.y = geometry->y - py - + ((edges & SWC_WINDOW_EDGE_BOTTOM) ? geometry->height : 0); + window->resize.offset.x = geometry->x - px + ((edges & SWC_WINDOW_EDGE_RIGHT) ? geometry->width : 0); + window->resize.offset.y = geometry->y - py + ((edges & SWC_WINDOW_EDGE_BOTTOM) ? geometry->height : 0); window->resize.edges = edges; } diff --git a/libswc/window.h b/libswc/window.h @@ -53,8 +53,7 @@ struct window { bool managed; unsigned mode; - struct - { + struct { struct window_pointer_interaction interaction; struct { int32_t x, y; @@ -64,8 +63,7 @@ struct window { int32_t x, y; } move; - struct - { + struct { struct window_pointer_interaction interaction; struct { int32_t x, y; @@ -73,8 +71,7 @@ struct window { uint32_t edges; } resize; - struct - { + struct { bool pending, acknowledged; uint32_t width, height; } configure; @@ -91,25 +88,14 @@ struct window_impl { extern struct wl_listener window_enter_listener; -bool window_initialize(struct window *window, const struct window_impl *impl, - struct surface *surface); - +bool window_initialize(struct window *window, const struct window_impl *impl, struct surface *surface); void window_finalize(struct window *window); - void window_manage(struct window *window); - void window_unmanage(struct window *window); - -void window_set_title(struct window *window, - const char *title, size_t length); - +void window_set_title(struct window *window, const char *title, size_t length); void window_set_app_id(struct window *window, const char *app_id); - void window_set_parent(struct window *window, struct window *parent); - void window_begin_move(struct window *window, struct button *button); - -void window_begin_resize(struct window *window, uint32_t edges, - struct button *button); +void window_begin_resize(struct window *window, uint32_t edges, struct button *button); #endif diff --git a/libswc/xdg_popup.c b/libswc/xdg_popup.c @@ -43,14 +43,13 @@ destroy(struct wl_client *client, struct wl_resource *resource) } static const struct xdg_popup_interface xdg_popup_implementation = { - .destroy = &destroy + .destroy = destroy, }; static void handle_surface_destroy(struct wl_listener *listener, void *data) { struct xdg_popup *popup = wl_container_of(listener, popup, surface_destroy_listener); - wl_resource_destroy(popup->resource); } @@ -65,11 +64,8 @@ destroy_popup(struct wl_resource *resource) } struct xdg_popup * -xdg_popup_new(struct wl_client *client, - uint32_t version, uint32_t id, - struct surface *surface, - struct surface *parent_surface, - int32_t x, int32_t y) +xdg_popup_new(struct wl_client *client, uint32_t version, + uint32_t id, struct surface *surface, struct surface *parent_surface, int32_t x, int32_t y) { struct xdg_popup *popup; struct compositor_view *parent = compositor_view(parent_surface->view); @@ -82,23 +78,19 @@ xdg_popup_new(struct wl_client *client, if (!popup) goto error0; - popup->resource = wl_resource_create(client, &xdg_popup_interface, - version, id); + popup->resource = wl_resource_create(client, &xdg_popup_interface, version, id); if (!popup->resource) goto error1; popup->surface_destroy_listener.notify = &handle_surface_destroy; - wl_resource_add_destroy_listener(surface->resource, - &popup->surface_destroy_listener); - wl_resource_set_implementation(popup->resource, &xdg_popup_implementation, - popup, &destroy_popup); + wl_resource_add_destroy_listener(surface->resource, &popup->surface_destroy_listener); + wl_resource_set_implementation(popup->resource, &xdg_popup_implementation, popup, &destroy_popup); if (!(popup->view = compositor_create_view(surface))) goto error2; - view_move(&popup->view->base, - parent->base.geometry.x + x, parent->base.geometry.y + y); + view_move(&popup->view->base, parent->base.geometry.x + x, parent->base.geometry.y + y); compositor_view_set_parent(popup->view, parent); return popup; diff --git a/libswc/xdg_popup.h b/libswc/xdg_popup.h @@ -29,10 +29,7 @@ struct surface; struct wl_client; -struct xdg_popup *xdg_popup_new(struct wl_client *client, - uint32_t version, uint32_t id, - struct surface *surface, - struct surface *parent, - int32_t x, int32_t y); +struct xdg_popup *xdg_popup_new(struct wl_client *client, uint32_t version, uint32_t id, + struct surface *surface, struct surface *parent, int32_t x, int32_t y); #endif diff --git a/libswc/xdg_shell.c b/libswc/xdg_shell.c @@ -35,8 +35,7 @@ static_assert(XDG_SHELL_VERSION == XDG_SHELL_VERSION_CURRENT, "xdg_shell implementation does not match protocol version"); -static struct - { +static struct { struct wl_global *global; } shell; @@ -47,64 +46,53 @@ destroy(struct wl_client *client, struct wl_resource *resource) } static void -use_unstable_version(struct wl_client *client, - struct wl_resource *resource, int32_t version) +use_unstable_version(struct wl_client *client, struct wl_resource *resource, int32_t version) { } static void -get_xdg_surface(struct wl_client *client, - struct wl_resource *resource, uint32_t id, - struct wl_resource *surface_resource) +get_xdg_surface(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource) { struct surface *surface = wl_resource_get_user_data(surface_resource); struct xdg_surface *xdg_surface; - xdg_surface = xdg_surface_new(client, wl_resource_get_version(resource), id, - surface); + xdg_surface = xdg_surface_new(client, wl_resource_get_version(resource), id, surface); if (!xdg_surface) wl_resource_post_no_memory(resource); } static void -get_xdg_popup(struct wl_client *client, - struct wl_resource *resource, uint32_t id, - struct wl_resource *surface_resource, - struct wl_resource *parent_resource, - struct wl_resource *seat_resource, - uint32_t serial, int32_t x, int32_t y) +get_xdg_popup(struct wl_client *client, struct wl_resource *resource, + uint32_t id, struct wl_resource *surface_resource, struct wl_resource *parent_resource, + struct wl_resource *seat_resource, uint32_t serial, int32_t x, int32_t y) { struct surface *surface = wl_resource_get_user_data(surface_resource); struct surface *parent = wl_resource_get_user_data(parent_resource); struct xdg_popup *popup; - popup = xdg_popup_new(client, wl_resource_get_version(resource), id, - surface, parent, x, y); + popup = xdg_popup_new(client, wl_resource_get_version(resource), id, surface, parent, x, y); if (!popup) wl_resource_post_no_memory(resource); } static void -pong(struct wl_client *client, struct wl_resource *resource, - uint32_t serial) +pong(struct wl_client *client, struct wl_resource *resource, uint32_t serial) { } static const struct xdg_shell_interface shell_implementation = { - .destroy = &destroy, - .use_unstable_version = &use_unstable_version, - .get_xdg_surface = &get_xdg_surface, - .get_xdg_popup = &get_xdg_popup, - .pong = &pong + .destroy = destroy, + .use_unstable_version = use_unstable_version, + .get_xdg_surface = get_xdg_surface, + .get_xdg_popup = get_xdg_popup, + .pong = pong, }; static int unversioned_dispatch(const void *implementation, void *target, - uint32_t opcode, - const struct wl_message *message, - union wl_argument *arguments) + uint32_t opcode, const struct wl_message *message, union wl_argument *arguments) { struct wl_resource *resource = target; @@ -116,8 +104,7 @@ unversioned_dispatch(const void *implementation, void *target, if (arguments[0].i != XDG_SHELL_VERSION) { wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, - "incompatible xdg_shell versions, " - "server: %d, client: %d", + "incompatible xdg_shell versions, server: %d, client: %d", XDG_SHELL_VERSION, arguments[0].i); return 0; } @@ -127,8 +114,7 @@ unversioned_dispatch(const void *implementation, void *target, } static void -bind_shell(struct wl_client *client, void *data, - uint32_t version, uint32_t id) +bind_shell(struct wl_client *client, void *data, uint32_t version, uint32_t id) { struct wl_resource *resource; @@ -136,16 +122,13 @@ bind_shell(struct wl_client *client, void *data, version = 1; resource = wl_resource_create(client, &xdg_shell_interface, version, id); - wl_resource_set_dispatcher(resource, &unversioned_dispatch, - NULL, NULL, NULL); + wl_resource_set_dispatcher(resource, &unversioned_dispatch, NULL, NULL, NULL); } bool xdg_shell_initialize(void) { - shell.global = wl_global_create(swc.display, &xdg_shell_interface, 1, - NULL, &bind_shell); - + shell.global = wl_global_create(swc.display, &xdg_shell_interface, 1, NULL, &bind_shell); return shell.global; } diff --git a/libswc/xdg_surface.c b/libswc/xdg_surface.c @@ -82,9 +82,7 @@ configure(struct window *window, uint32_t width, uint32_t height) window->configure.acknowledged = false; xdg_surface->configure_serial = wl_display_next_serial(swc.display); - xdg_surface_send_configure(xdg_surface->resource, width, height, - &xdg_surface->states, - xdg_surface->configure_serial); + xdg_surface_send_configure(xdg_surface->resource, width, height, &xdg_surface->states, xdg_surface->configure_serial); } static void @@ -152,11 +150,9 @@ destroy(struct wl_client *client, struct wl_resource *resource) } static void -set_parent(struct wl_client *client, struct wl_resource *resource, - struct wl_resource *parent_resource) +set_parent(struct wl_client *client, struct wl_resource *resource, struct wl_resource *parent_resource) { - struct xdg_surface *xdg_surface = wl_resource_get_user_data(resource), - *parent_surface; + struct xdg_surface *xdg_surface = wl_resource_get_user_data(resource), *parent_surface; struct window *parent_window = NULL; if (parent_resource) { @@ -168,34 +164,27 @@ set_parent(struct wl_client *client, struct wl_resource *resource, } static void -set_title(struct wl_client *client, struct wl_resource *resource, - const char *title) +set_title(struct wl_client *client, struct wl_resource *resource, const char *title) { struct xdg_surface *xdg_surface = wl_resource_get_user_data(resource); - window_set_title(&xdg_surface->window, title, -1); } static void -set_app_id(struct wl_client *client, struct wl_resource *resource, - const char *app_id) +set_app_id(struct wl_client *client, struct wl_resource *resource, const char *app_id) { struct xdg_surface *surface = wl_resource_get_user_data(resource); - window_set_app_id(&surface->window, app_id); } static void -show_window_menu(struct wl_client *client, - struct wl_resource *resource, - struct wl_resource *seat_resource, - uint32_t serial, int32_t x, int32_t y) +show_window_menu(struct wl_client *client, struct wl_resource *resource, + struct wl_resource *seat_resource, uint32_t serial, int32_t x, int32_t y) { } static void -move(struct wl_client *client, struct wl_resource *resource, - struct wl_resource *seat_resource, uint32_t serial) +move(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { struct xdg_surface *xdg_surface = wl_resource_get_user_data(resource); struct button *button; @@ -208,8 +197,7 @@ move(struct wl_client *client, struct wl_resource *resource, static void resize(struct wl_client *client, struct wl_resource *resource, - struct wl_resource *seat_resource, uint32_t serial, - uint32_t edges) + struct wl_resource *seat_resource, uint32_t serial, uint32_t edges) { struct xdg_surface *xdg_surface = wl_resource_get_user_data(resource); struct button *button; @@ -221,8 +209,7 @@ resize(struct wl_client *client, struct wl_resource *resource, } static void -ack_configure(struct wl_client *client, - struct wl_resource *resource, uint32_t serial) +ack_configure(struct wl_client *client, struct wl_resource *resource, uint32_t serial) { struct xdg_surface *xdg_surface = wl_resource_get_user_data(resource); @@ -231,72 +218,63 @@ ack_configure(struct wl_client *client, } static void -set_window_geometry(struct wl_client *client, - struct wl_resource *resource, - int32_t x, int32_t y, - int32_t width, int32_t height) +set_window_geometry(struct wl_client *client, struct wl_resource *resource, + int32_t x, int32_t y, int32_t width, int32_t height) { /* TODO: Implement set_window_geometry. */ } static void -set_maximized(struct wl_client *client, - struct wl_resource *resource) +set_maximized(struct wl_client *client, struct wl_resource *resource) { /* TODO: Implement set_maximized. */ } static void -unset_maximized(struct wl_client *client, - struct wl_resource *resource) +unset_maximized(struct wl_client *client, struct wl_resource *resource) { /* TODO: Implement unset_maximized. */ } static void -set_fullscreen(struct wl_client *client, - struct wl_resource *resource, - struct wl_resource *output_resource) +set_fullscreen(struct wl_client *client, struct wl_resource *resource, struct wl_resource *output_resource) { /* TODO: Implement set_fullscreen. */ } static void -unset_fullscreen(struct wl_client *client, - struct wl_resource *resource) +unset_fullscreen(struct wl_client *client, struct wl_resource *resource) { /* TODO: Implement unset_fullscreen. */ } static void -set_minimized(struct wl_client *client, - struct wl_resource *resource) +set_minimized(struct wl_client *client, struct wl_resource *resource) { /* TODO: Implement set_minimized. */ } static const struct xdg_surface_interface xdg_surface_implementation = { - .destroy = &destroy, - .set_parent = &set_parent, - .set_title = &set_title, - .set_app_id = &set_app_id, - .show_window_menu = &show_window_menu, - .move = &move, - .resize = &resize, - .ack_configure = &ack_configure, - .set_window_geometry = &set_window_geometry, - .set_maximized = &set_maximized, - .unset_maximized = &unset_maximized, - .set_fullscreen = &set_fullscreen, - .unset_fullscreen = &unset_fullscreen, - .set_minimized = &set_minimized, + .destroy = destroy, + .set_parent = set_parent, + .set_title = set_title, + .set_app_id = set_app_id, + .show_window_menu = show_window_menu, + .move = move, + .resize = resize, + .ack_configure = ack_configure, + .set_window_geometry = set_window_geometry, + .set_maximized = set_maximized, + .unset_maximized = unset_maximized, + .set_fullscreen = set_fullscreen, + .unset_fullscreen = unset_fullscreen, + .set_minimized = set_minimized, }; static void handle_surface_destroy(struct wl_listener *listener, void *data) { struct xdg_surface *xdg_surface = wl_container_of(listener, xdg_surface, surface_destroy_listener); - wl_resource_destroy(xdg_surface->resource); } @@ -311,9 +289,7 @@ destroy_xdg_surface(struct wl_resource *resource) } struct xdg_surface * -xdg_surface_new(struct wl_client *client, - uint32_t version, uint32_t id, - struct surface *surface) +xdg_surface_new(struct wl_client *client, uint32_t version, uint32_t id, struct surface *surface) { struct xdg_surface *xdg_surface; @@ -322,8 +298,7 @@ xdg_surface_new(struct wl_client *client, if (!xdg_surface) goto error0; - xdg_surface->resource = wl_resource_create(client, &xdg_surface_interface, - version, id); + xdg_surface->resource = wl_resource_create(client, &xdg_surface_interface, version, id); if (!xdg_surface->resource) goto error1; @@ -331,11 +306,8 @@ xdg_surface_new(struct wl_client *client, window_initialize(&xdg_surface->window, &xdg_surface_window_impl, surface); xdg_surface->surface_destroy_listener.notify = &handle_surface_destroy; wl_array_init(&xdg_surface->states); - wl_resource_add_destroy_listener(surface->resource, - &xdg_surface->surface_destroy_listener); - wl_resource_set_implementation(xdg_surface->resource, - &xdg_surface_implementation, - xdg_surface, &destroy_xdg_surface); + wl_resource_add_destroy_listener(surface->resource, &xdg_surface->surface_destroy_listener); + wl_resource_set_implementation(xdg_surface->resource, &xdg_surface_implementation, xdg_surface, &destroy_xdg_surface); window_manage(&xdg_surface->window); return xdg_surface; diff --git a/libswc/xdg_surface.h b/libswc/xdg_surface.h @@ -29,8 +29,6 @@ struct surface; struct wl_client; -struct xdg_surface *xdg_surface_new(struct wl_client *client, - uint32_t version, uint32_t id, - struct surface *surface); +struct xdg_surface *xdg_surface_new(struct wl_client *client, uint32_t version, uint32_t id, struct surface *surface); #endif diff --git a/libswc/xkb.c b/libswc/xkb.c @@ -103,8 +103,7 @@ xkb_update_keymap(struct xkb *xkb) { const char *keymap_directory = getenv("XDG_RUNTIME_DIR") ?: "/tmp"; char *keymap_string; - char keymap_path[strlen(keymap_directory) + 1 - + sizeof keymap_file_template]; + char keymap_path[strlen(keymap_directory) + 1 + sizeof keymap_file_template]; xkb->indices.ctrl = xkb_keymap_mod_get_index(xkb->keymap.map, XKB_MOD_NAME_CTRL); xkb->indices.alt = xkb_keymap_mod_get_index(xkb->keymap.map, XKB_MOD_NAME_ALT); @@ -113,8 +112,7 @@ xkb_update_keymap(struct xkb *xkb) /* In order to send the keymap to clients, we must first convert it to a * string and then mmap it to a file. */ - keymap_string = xkb_keymap_get_as_string(xkb->keymap.map, - XKB_KEYMAP_FORMAT_TEXT_V1); + keymap_string = xkb_keymap_get_as_string(xkb->keymap.map, XKB_KEYMAP_FORMAT_TEXT_V1); if (!keymap_string) { WARNING("Could not get XKB keymap as a string\n"); @@ -138,8 +136,7 @@ xkb_update_keymap(struct xkb *xkb) goto error2; } - xkb->keymap.area = mmap(NULL, xkb->keymap.size, PROT_READ | PROT_WRITE, - MAP_SHARED, xkb->keymap.fd, 0); + xkb->keymap.area = mmap(NULL, xkb->keymap.size, PROT_READ | PROT_WRITE, MAP_SHARED, xkb->keymap.fd, 0); if (xkb->keymap.area == MAP_FAILED) { WARNING("Could not mmap XKB keymap string\n"); diff --git a/libswc/xkb.h b/libswc/xkb.h @@ -34,16 +34,14 @@ struct xkb { struct xkb_context *context; struct xkb_state *state; - struct - { + struct { struct xkb_keymap *map; int fd; uint32_t size; char *area; } keymap; - struct - { + struct { uint32_t ctrl, alt, super, shift; } indices; }; @@ -51,7 +49,6 @@ struct xkb { bool xkb_initialize(struct xkb *xkb); void xkb_finalize(struct xkb *xkb); bool xkb_reset_state(struct xkb *xkb); - bool xkb_update_keymap(struct xkb *xkb); #endif diff --git a/libswc/xserver.c b/libswc/xserver.c @@ -44,8 +44,7 @@ #define SOCKET_DIR "/tmp/.X11-unix" #define SOCKET_FMT SOCKET_DIR "/X%d" -static struct - { +static struct { struct wl_resource *resource; struct wl_event_source *usr1_source; int display; @@ -65,7 +64,7 @@ open_socket(struct sockaddr_un *addr, size_t path_size) goto error0; /* Unlink the socket location in case it was being used by a process which - * left around a stale lockfile. */ + * left around a stale lockfile. */ unlink(addr->sun_path); if (bind(fd, (struct sockaddr *)addr, size) < 0) @@ -90,7 +89,7 @@ open_display(void) { char lock_name[64], pid[12]; int lock_fd; - struct sockaddr_un addr = {.sun_family = AF_LOCAL }; + struct sockaddr_un addr = {.sun_family = AF_LOCAL}; size_t path_size; xserver.display = 0; @@ -149,20 +148,17 @@ begin: /* Bind to abstract socket */ addr.sun_path[0] = '\0'; - path_size = snprintf(addr.sun_path + 1, sizeof addr.sun_path - 1, - SOCKET_FMT, xserver.display); + path_size = snprintf(addr.sun_path + 1, sizeof addr.sun_path - 1, SOCKET_FMT, xserver.display); if ((xserver.abstract_fd = open_socket(&addr, path_size)) < 0) goto retry1; /* Bind to unix socket */ mkdir(SOCKET_DIR, 0777); - path_size = snprintf(addr.sun_path, sizeof addr.sun_path, - SOCKET_FMT, xserver.display); + path_size = snprintf(addr.sun_path, sizeof addr.sun_path, SOCKET_FMT, xserver.display); if ((xserver.unix_fd = open_socket(&addr, path_size)) < 0) goto retry2; - snprintf(xserver.display_name, sizeof xserver.display_name, - ":%d", xserver.display); + snprintf(xserver.display_name, sizeof xserver.display_name, ":%d", xserver.display); setenv("DISPLAY", xserver.display_name, true); return true; @@ -208,8 +204,7 @@ xserver_initialize(void) goto error0; } - xserver.usr1_source = wl_event_loop_add_signal(swc.event_loop, SIGUSR1, - &handle_usr1, NULL); + xserver.usr1_source = wl_event_loop_add_signal(swc.event_loop, SIGUSR1, &handle_usr1, NULL); if (!xserver.usr1_source) { ERROR("Failed to create SIGUSR1 event source\n"); @@ -241,27 +236,24 @@ xserver_initialize(void) unsigned index; struct sigaction action = {.sa_handler = SIG_IGN }; - /* Unset the FD_CLOEXEC flag on the FDs that will get passed to - * Xwayland. */ + /* Unset the FD_CLOEXEC flag on the FDs that will get passed to Xwayland. */ for (index = 0; index < ARRAY_LENGTH(fds); ++index) { if (fcntl(fds[index], F_SETFD, 0) != 0) { ERROR("fcntl() failed: %s\n", strerror(errno)); goto fail; } - if (snprintf(strings[index], sizeof strings[index], - "%d", fds[index]) >= sizeof strings[index]) { + if (snprintf(strings[index], sizeof strings[index], "%d", fds[index]) >= sizeof strings[index]) { ERROR("FD is too large\n"); goto fail; } } - /* Ignore the USR1 signal so that Xwayland will send a USR1 signal - * to the parent process (us) after it finishes initializing. See - * Xserver(1) for more details. */ + /* Ignore the USR1 signal so that Xwayland will send a USR1 signal to the + * parent process (us) after it finishes initializing. See Xserver(1) for + * more details. */ if (sigaction(SIGUSR1, &action, NULL) != 0) { - ERROR("Failed to set SIGUSR1 handler to SIG_IGN: %s\n", - strerror(errno)); + ERROR("Failed to set SIGUSR1 handler to SIG_IGN: %s\n", strerror(errno)); goto fail; } @@ -279,8 +271,7 @@ xserver_initialize(void) exit(EXIT_FAILURE); } case -1: - ERROR("fork() failed when trying to start X server: %s\n", - strerror(errno)); + ERROR("fork() failed when trying to start X server: %s\n", strerror(errno)); goto error5; } diff --git a/libswc/xwm.c b/libswc/xwm.c @@ -56,8 +56,7 @@ enum atom { ATOM_WM_S0, }; -static struct - { +static struct { xcb_connection_t *connection; xcb_ewmh_connection_t ewmh; xcb_screen_t *screen; @@ -72,10 +71,10 @@ static struct } atoms[4]; } xwm = { .atoms = { - [ATOM_WL_SURFACE_ID] = "WL_SURFACE_ID", - [ATOM_WM_DELETE_WINDOW] = "WM_DELETE_WINDOW", - [ATOM_WM_PROTOCOLS] = "WM_PROTOCOLS", - [ATOM_WM_S0] = "WM_S0", + [ATOM_WL_SURFACE_ID] = "WL_SURFACE_ID", + [ATOM_WM_DELETE_WINDOW] = "WM_DELETE_WINDOW", + [ATOM_WM_PROTOCOLS] = "WM_PROTOCOLS", + [ATOM_WM_S0] = "WM_S0", } }; @@ -87,14 +86,12 @@ update_name(struct xwl_window *xwl_window) wm_name_cookie = xcb_ewmh_get_wm_name(&xwm.ewmh, xwl_window->id); - if (xcb_ewmh_get_wm_name_reply(&xwm.ewmh, wm_name_cookie, - &wm_name_reply, NULL)) { - window_set_title(&xwl_window->window, - wm_name_reply.strings, wm_name_reply.strings_len); - + if (xcb_ewmh_get_wm_name_reply(&xwm.ewmh, wm_name_cookie, &wm_name_reply, NULL)) { + window_set_title(&xwl_window->window, wm_name_reply.strings, wm_name_reply.strings_len); xcb_ewmh_get_utf8_strings_reply_wipe(&wm_name_reply); - } else + } else { window_set_title(&xwl_window->window, NULL, 0); + } } static void @@ -104,9 +101,7 @@ update_protocols(struct xwl_window *xwl_window) xcb_icccm_get_wm_protocols_reply_t reply; unsigned index; - cookie = xcb_icccm_get_wm_protocols(xwm.connection, xwl_window->id, - xwm.atoms[ATOM_WM_PROTOCOLS].value); - + cookie = xcb_icccm_get_wm_protocols(xwm.connection, xwl_window->id, xwm.atoms[ATOM_WM_PROTOCOLS].value); xwl_window->supports_delete = true; if (!xcb_icccm_get_wm_protocols_reply(xwm.connection, cookie, &reply, NULL)) @@ -134,8 +129,7 @@ find_window(struct wl_list *list, xcb_window_t id) } static struct xwl_window * -find_window_by_surface_id(struct wl_list *list, - uint32_t id) +find_window_by_surface_id(struct wl_list *list, uint32_t id) { struct xwl_window *window; @@ -181,8 +175,7 @@ focus(struct window *window) { struct xwl_window *xwl_window = wl_container_of(window, xwl_window, window); - xcb_set_input_focus(xwm.connection, XCB_INPUT_FOCUS_NONE, - xwl_window->id, XCB_CURRENT_TIME); + xcb_set_input_focus(xwm.connection, XCB_INPUT_FOCUS_NONE, xwl_window->id, XCB_CURRENT_TIME); xcb_flush(xwm.connection); xwm.focus = xwl_window; } @@ -192,13 +185,12 @@ unfocus(struct window *window) { struct xwl_window *xwl_window = wl_container_of(window, xwl_window, window); - /* If the window we are unfocusing is the latest xwl_window to be focused, - * we know we have transitioned to some other window type, so the X11 focus - * can be set to XCB_NONE. Otherwise, we have transitioned to another X11 - * window, and the X11 focus has already been updated. */ + /* If the window we are unfocusing is the latest xwl_window to be focused, we + * know we have transitioned to some other window type, so the X11 focus can + * be set to XCB_NONE. Otherwise, we have transitioned to another X11 window, + * and the X11 focus has already been updated. */ if (xwl_window == xwm.focus) { - xcb_set_input_focus(xwm.connection, XCB_INPUT_FOCUS_NONE, XCB_NONE, - XCB_CURRENT_TIME); + xcb_set_input_focus(xwm.connection, XCB_INPUT_FOCUS_NONE, XCB_NONE, XCB_CURRENT_TIME); xcb_flush(xwm.connection); } } @@ -215,25 +207,25 @@ close(struct window *window) .window = xwl_window->id, .type = xwm.atoms[ATOM_WM_PROTOCOLS].value, .data.data32 = { - xwm.atoms[ATOM_WM_DELETE_WINDOW].value, - XCB_CURRENT_TIME, + xwm.atoms[ATOM_WM_DELETE_WINDOW].value, + XCB_CURRENT_TIME, }, }; - xcb_send_event(xwm.connection, false, xwl_window->id, - XCB_EVENT_MASK_NO_EVENT, (const char *)&event); - } else + xcb_send_event(xwm.connection, false, xwl_window->id, XCB_EVENT_MASK_NO_EVENT, (const char *)&event); + } else { xcb_kill_client(xwm.connection, xwl_window->id); + } xcb_flush(xwm.connection); } static const struct window_impl xwl_window_handler = { - .move = &move, - .configure = &configure, - .focus = &focus, - .unfocus = &unfocus, - .close = &close, + .move = move, + .configure = configure, + .focus = focus, + .unfocus = unfocus, + .close = close, }; static void @@ -258,8 +250,7 @@ manage_window(struct xwl_window *xwl_window) xcb_get_geometry_cookie_t geometry_cookie; xcb_get_geometry_reply_t *geometry_reply; - resource = wl_client_get_object(swc.xserver->client, - xwl_window->surface_id); + resource = wl_client_get_object(swc.xserver->client, xwl_window->surface_id); if (!resource) return false; @@ -269,24 +260,21 @@ manage_window(struct xwl_window *xwl_window) window_initialize(&xwl_window->window, &xwl_window_handler, surface); xwl_window->surface_destroy_listener.notify = &handle_surface_destroy; - wl_resource_add_destroy_listener(surface->resource, - &xwl_window->surface_destroy_listener); + wl_resource_add_destroy_listener(surface->resource, &xwl_window->surface_destroy_listener); - if ((geometry_reply = xcb_get_geometry_reply(xwm.connection, - geometry_cookie, NULL))) { + if ((geometry_reply = xcb_get_geometry_reply(xwm.connection, geometry_cookie, NULL))) { view_move(surface->view, geometry_reply->x, geometry_reply->y); free(geometry_reply); } - if (xwl_window->override_redirect) + if (xwl_window->override_redirect) { compositor_view_show(xwl_window->window.view); - else { + } else { uint32_t mask, values[1]; mask = XCB_CW_EVENT_MASK; values[0] = XCB_EVENT_MASK_PROPERTY_CHANGE; - xcb_change_window_attributes(xwm.connection, xwl_window->id, - mask, values); + xcb_change_window_attributes(xwm.connection, xwl_window->id, mask, values); mask = XCB_CONFIG_WINDOW_BORDER_WIDTH; values[0] = 0; xcb_configure_window(xwm.connection, xwl_window->id, mask, values); @@ -307,8 +295,7 @@ handle_new_surface(struct wl_listener *listener, void *data) struct surface *surface = data; struct xwl_window *window; - window = find_window_by_surface_id(&xwm.unpaired_windows, - wl_resource_get_id(surface->resource)); + window = find_window_by_surface_id(&xwm.unpaired_windows, wl_resource_get_id(surface->resource)); if (!window) return; @@ -343,8 +330,9 @@ destroy_notify(xcb_destroy_notify_event_t *event) if ((xwl_window = find_window(&xwm.windows, event->window))) { wl_list_remove(&xwl_window->surface_destroy_listener.link); window_finalize(&xwl_window->window); - } else if (!(xwl_window = find_window(&xwm.unpaired_windows, event->window))) + } else if (!(xwl_window = find_window(&xwm.unpaired_windows, event->window))) { return; + } wl_list_remove(&xwl_window->link); free(xwl_window); @@ -369,10 +357,9 @@ property_notify(xcb_property_notify_event_t *event) if (!(xwl_window = find_window(&xwm.windows, event->window))) return; - if (event->atom == xwm.ewmh._NET_WM_NAME - && event->state == XCB_PROPERTY_NEW_VALUE) { + if (event->atom == xwm.ewmh._NET_WM_NAME && event->state == XCB_PROPERTY_NEW_VALUE) update_name(xwl_window); - } else if (event->atom == xwm.atoms[ATOM_WM_PROTOCOLS].value) + else if (event->atom == xwm.atoms[ATOM_WM_PROTOCOLS].value) update_protocols(xwl_window); } @@ -459,8 +446,7 @@ xwm_initialize(int fd) for (index = 0; index < ARRAY_LENGTH(xwm.atoms); ++index) { name = xwm.atoms[index].name; - xwm.atoms[index].cookie = xcb_intern_atom(xwm.connection, 0, - strlen(name), name); + xwm.atoms[index].cookie = xcb_intern_atom(xwm.connection, 0, strlen(name), name); } setup = xcb_get_setup(xwm.connection); @@ -469,12 +455,10 @@ xwm_initialize(int fd) /* Try to select for substructure redirect. */ mask = XCB_CW_EVENT_MASK; - values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY - | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT; + values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT; change_attributes_cookie = xcb_change_window_attributes(xwm.connection, xwm.screen->root, mask, values); - xwm.source = wl_event_loop_add_fd(swc.event_loop, fd, WL_EVENT_READABLE, - &connection_data, NULL); + xwm.source = wl_event_loop_add_fd(swc.event_loop, fd, WL_EVENT_READABLE, &connection_data, NULL); wl_list_init(&xwm.windows); wl_list_init(&xwm.unpaired_windows); @@ -517,8 +501,7 @@ xwm_initialize(int fd) } for (index = 0; index < ARRAY_LENGTH(xwm.atoms); ++index) { - atom_reply = xcb_intern_atom_reply(xwm.connection, - xwm.atoms[index].cookie, &error); + atom_reply = xcb_intern_atom_reply(xwm.connection, xwm.atoms[index].cookie, &error); if (error) { ERROR("xwm: Failed to get atom reply: %u\n", error->error_code); @@ -529,8 +512,7 @@ xwm_initialize(int fd) free(atom_reply); } - xcb_set_selection_owner(xwm.connection, xwm.window, - xwm.atoms[ATOM_WM_S0].value, XCB_CURRENT_TIME); + xcb_set_selection_owner(xwm.connection, xwm.window, xwm.atoms[ATOM_WM_S0].value, XCB_CURRENT_TIME); xcb_flush(xwm.connection); wl_signal_add(&swc.compositor->signal.new_surface, &new_surface_listener);