Skip to content

Commit

Permalink
Use clang-format to ensure correct format of the changed files.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanfanel committed Feb 12, 2024
1 parent 84c5125 commit ae083cf
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 59 deletions.
2 changes: 1 addition & 1 deletion cage.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#include <wlr/types/wlr_idle_notify_v1.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output_management_v1.h>
#include <wlr/types/wlr_pointer_constraints_v1.h>
#include <wlr/types/wlr_presentation_time.h>
#include <wlr/types/wlr_relative_pointer_v1.h>
#include <wlr/types/wlr_pointer_constraints_v1.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_screencopy_v1.h>
#include <wlr/types/wlr_server_decoration.h>
Expand Down
117 changes: 61 additions & 56 deletions seat.c
Original file line number Diff line number Diff line change
Expand Up @@ -630,21 +630,20 @@ process_cursor_motion(struct cg_seat *seat, uint32_t time_msec, double *dx, doub
dy_unaccel);
}

/* Apply pointer constraints. It has to be done before calling wlr_cursor_move() */
/* Apply pointer constraints. It has to be done before calling wlr_cursor_move() */
if (seat->active_constraint) {
double sx_confined, sy_confined;
/* wlr_region_confine() checks if the current position is within a confinement region.
* If it is, returns true and takes the next position after a move and ajusts it
* to the confinement region.
* It it's not, it returns false and does nothing.
* seat->confine: confinement region.
* sx/sy:current position.
* sx+dx/sy+dy: next position after a move.
* sx_confined/sy_confined: next position, but confined to the region.
*/
if (!wlr_region_confine(&seat->confine, sx, sy, sx + *dx, sy + *dy,
&sx_confined, &sy_confined)) {
return;
/* wlr_region_confine() checks if the current position is within a confinement region.
* If it is, returns true and takes the next position after a move and ajusts it
* to the confinement region.
* It it's not, it returns false and does nothing.
* seat->confine: confinement region.
* sx/sy:current position.
* sx+dx/sy+dy: next position after a move.
* sx_confined/sy_confined: next position, but confined to the region.
*/
if (!wlr_region_confine(&seat->confine, sx, sy, sx + *dx, sy + *dy, &sx_confined, &sy_confined)) {
return;
}

*dx = sx_confined - sx;
Expand All @@ -659,11 +658,12 @@ process_cursor_motion(struct cg_seat *seat, uint32_t time_msec, double *dx, doub
wlr_idle_notifier_v1_notify_activity(seat->server->idle, seat->seat);
}

static void warp_to_constraint_cursor_hint(struct cg_seat *seat) {
static void
warp_to_constraint_cursor_hint(struct cg_seat *seat)
{
struct wlr_pointer_constraint_v1 *constraint = seat->active_constraint;

if (constraint->current.committed &
WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) {
if (constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) {
double sx = constraint->current.cursor_hint.x;
double sy = constraint->current.cursor_hint.y;

Expand All @@ -680,7 +680,9 @@ static void warp_to_constraint_cursor_hint(struct cg_seat *seat) {
}
}

static void check_constraint_region(struct cg_seat *seat) {
static void
check_constraint_region(struct cg_seat *seat)
{
struct wlr_pointer_constraint_v1 *constraint = seat->active_constraint;
pixman_region32_t *region = &constraint->region;
if (seat->active_confine_requires_warp) {
Expand All @@ -689,16 +691,15 @@ static void check_constraint_region(struct cg_seat *seat) {
double sx = seat->cursor->x;
double sy = seat->cursor->y;

if (!pixman_region32_contains_point(region,
floor(sx), floor(sy), NULL)) {
if (!pixman_region32_contains_point(region, floor(sx), floor(sy), NULL)) {
int nboxes;
pixman_box32_t *boxes = pixman_region32_rectangles(region, &nboxes);
if (nboxes > 0) {
double sx = (boxes[0].x1 + boxes[0].x2) / 2.;
double sy = (boxes[0].y1 + boxes[0].y2) / 2.;

wlr_cursor_warp_closest(seat->cursor, NULL, sx, sy);
//cursor_rebase(seat);
// cursor_rebase(seat);
}
}
}
Expand All @@ -711,10 +712,10 @@ static void check_constraint_region(struct cg_seat *seat) {
}
}

static void handle_constraint_commit(struct wl_listener *listener,
void *data) {
struct cg_seat *seat =
wl_container_of(listener, seat, constraint_commit);
static void
handle_constraint_commit(struct wl_listener *listener, void *data)
{
struct cg_seat *seat = wl_container_of(listener, seat, constraint_commit);
struct wlr_pointer_constraint_v1 *constraint = seat->active_constraint;
assert(constraint->surface == data);

Expand All @@ -723,8 +724,9 @@ static void handle_constraint_commit(struct wl_listener *listener,

/* This is where active_constraint is assigned. Also remember that everything
* Sway has in sway_cursor is in cg_seat, because in Cage there's only a cursor per seat. */
void cg_cursor_constrain(struct cg_seat *seat,
struct wlr_pointer_constraint_v1 *constraint) {
void
cg_cursor_constrain(struct cg_seat *seat, struct wlr_pointer_constraint_v1 *constraint)
{

if (seat->active_constraint == constraint) {
return;
Expand All @@ -735,8 +737,7 @@ void cg_cursor_constrain(struct cg_seat *seat,
if (constraint == NULL) {
warp_to_constraint_cursor_hint(seat);
}
wlr_pointer_constraint_v1_send_deactivated(
seat->active_constraint);
wlr_pointer_constraint_v1_send_deactivated(seat->active_constraint);
}

seat->active_constraint = constraint;
Expand All @@ -754,35 +755,33 @@ void cg_cursor_constrain(struct cg_seat *seat,
// since this code will be run *after* the focus has been set.
// That is why we duplicate the code here.
if (pixman_region32_not_empty(&constraint->current.region)) {
pixman_region32_intersect(&constraint->region,
&constraint->surface->input_region, &constraint->current.region);
pixman_region32_intersect(&constraint->region, &constraint->surface->input_region,
&constraint->current.region);
} else {
pixman_region32_copy(&constraint->region,
&constraint->surface->input_region);
pixman_region32_copy(&constraint->region, &constraint->surface->input_region);
}

check_constraint_region(seat);

wlr_pointer_constraint_v1_send_activated(constraint);

seat->constraint_commit.notify = handle_constraint_commit;
wl_signal_add(&constraint->surface->events.commit,
&seat->constraint_commit);

wl_signal_add(&constraint->surface->events.commit, &seat->constraint_commit);
}

static void handle_pointer_constraint_set_region(struct wl_listener *listener,
void *data) {
struct cg_pointer_constraint *cg_constraint =
wl_container_of(listener, cg_constraint, set_region);
static void
handle_pointer_constraint_set_region(struct wl_listener *listener, void *data)
{
struct cg_pointer_constraint *cg_constraint = wl_container_of(listener, cg_constraint, set_region);
struct cg_seat *seat = cg_constraint->seat;

seat->active_confine_requires_warp = true;
}

void handle_constraint_destroy(struct wl_listener *listener, void *data) {
struct cg_pointer_constraint *cg_constraint =
wl_container_of(listener, cg_constraint, destroy);
void
handle_constraint_destroy(struct wl_listener *listener, void *data)
{
struct cg_pointer_constraint *cg_constraint = wl_container_of(listener, cg_constraint, destroy);
struct wlr_pointer_constraint_v1 *constraint = data;
struct cg_seat *seat = cg_constraint->seat;

Expand All @@ -802,25 +801,26 @@ void handle_constraint_destroy(struct wl_listener *listener, void *data) {
free(cg_constraint);
}

void handle_pointer_constraint(struct wl_listener *listener, void *data) {
void
handle_pointer_constraint(struct wl_listener *listener, void *data)
{
struct wlr_pointer_constraint_v1 *constraint = data;

/* Recover cg_seat from a wlr_seat's data field. Every wlr_seat has it's data field
set to the cg_seat containing it, in seat_create(). */
struct cg_seat *seat = constraint->seat->data;

struct cg_pointer_constraint *cg_constraint =
calloc(1, sizeof(struct cg_pointer_constraint));
/* Recover cg_seat from a wlr_seat's data field. Every wlr_seat has it's data field
set to the cg_seat containing it, in seat_create(). */
struct cg_seat *seat = constraint->seat->data;

struct cg_pointer_constraint *cg_constraint = calloc(1, sizeof(struct cg_pointer_constraint));
cg_constraint->constraint = constraint;
cg_constraint->seat = seat;

cg_constraint->set_region.notify = handle_pointer_constraint_set_region;
wl_signal_add(&constraint->events.set_region, &cg_constraint->set_region);

cg_constraint->destroy.notify = handle_constraint_destroy;
cg_constraint->destroy.notify = handle_constraint_destroy;
wl_signal_add(&constraint->events.destroy, &cg_constraint->destroy);

struct wlr_surface *surface = seat->seat->keyboard_state.focused_surface;
struct wlr_surface *surface = seat->seat->keyboard_state.focused_surface;
if (surface && surface == constraint->surface) {
cg_cursor_constrain(seat, constraint);
}
Expand Down Expand Up @@ -848,11 +848,16 @@ handle_cursor_motion_relative(struct wl_listener *listener, void *data)
{
struct cg_seat *seat = wl_container_of(listener, seat, cursor_motion_relative);
struct wlr_pointer_motion_event *event = data;
double dx = event->delta_x;
double dy = event->delta_y;
double dx = event->delta_x;
double dy = event->delta_y;

<<<<<<< HEAD
process_cursor_motion(seat, event->time_msec, &dx, &dy, event->unaccel_dx,
event->unaccel_dy);
=======
process_cursor_motion(seat, event->time_msec, &dx, &dy, event->unaccel_dx, event->unaccel_dy);

>>>>>>> c490ac1 (Use clang-format to ensure correct format of the changed files.)
wlr_cursor_move(seat->cursor, &event->pointer->base, dx, dy);
wlr_idle_notifier_v1_notify_activity(seat->server->idle, seat->seat);
}
Expand Down Expand Up @@ -1003,7 +1008,7 @@ seat_create(struct cg_server *server, struct wlr_backend *backend)
free(seat);
return NULL;
}
seat->seat->data = seat;
seat->seat->data = seat;
seat->server = server;
seat->destroy.notify = handle_destroy;
wl_signal_add(&seat->seat->events.destroy, &seat->destroy);
Expand Down Expand Up @@ -1149,8 +1154,8 @@ seat_set_focus(struct cg_seat *seat, struct cg_view *view)
wlr_seat_keyboard_notify_enter(wlr_seat, view->wlr_surface, NULL, 0, NULL);
}

double dx = 0, dy = 0;
process_cursor_motion(seat, -1, &dx, &dy, 0, 0);
double dx = 0, dy = 0;
process_cursor_motion(seat, -1, &dx, &dy, 0, 0);
}

void
Expand Down
4 changes: 2 additions & 2 deletions seat.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_pointer_constraints_v1.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_pointer_constraints_v1.h>

#include "server.h"
#include "view.h"
Expand Down Expand Up @@ -50,7 +50,7 @@ struct cg_seat {
struct wl_listener request_set_selection;
struct wl_listener request_set_primary_selection;

struct wl_listener constraint_commit;
struct wl_listener constraint_commit;
struct wlr_pointer_constraint_v1 *active_constraint;
pixman_region32_t confine; // invalid if active_constraint == NULL
bool active_confine_requires_warp;
Expand Down

0 comments on commit ae083cf

Please sign in to comment.