Skip to content

Commit

Permalink
fixed formatting; fixed minor logic bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
gg-rewrite committed Apr 14, 2020
1 parent 8eb5a82 commit b03c1bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 33 deletions.
12 changes: 3 additions & 9 deletions include/slurp.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,8 @@ struct slurp_seat {
// keyboard:
struct wl_keyboard *wl_keyboard;

//selection (pointer/touch):
/*struct slurp_output *current_output;
int32_t x, y;
int32_t anchor_x, anchor_y;
struct slurp_box selection;
bool has_selection;*/
struct slurp_selection pointer_selection;
struct slurp_selection touch_selection;
struct slurp_selection pointer_selection;
struct slurp_selection touch_selection;

// pointer:
struct wl_pointer *wl_pointer;
Expand All @@ -111,5 +105,5 @@ struct slurp_seat {
};

bool box_intersect(const struct slurp_box *a, const struct slurp_box *b);
struct slurp_selection* seat_get_current_selection(struct slurp_seat* seat);
struct slurp_selection* seat_get_current_selection(struct slurp_seat *seat);
#endif
12 changes: 5 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bool box_intersect(const struct slurp_box *a, const struct slurp_box *b) {
a->height + a->y > b->y;
}

struct slurp_selection *seat_get_current_selection(struct slurp_seat *seat) {
struct slurp_selection* seat_get_current_selection(struct slurp_seat *seat) {
if (seat->pointer_selection.has_selection) {
return &seat->pointer_selection;
} else if (seat->touch_selection.has_selection) {
Expand All @@ -44,8 +44,7 @@ static void move_seat(struct slurp_seat *seat, wl_fixed_t surface_x,
struct slurp_selection *current_selection =
seat_get_current_selection(seat);
if (current_selection == NULL) {
//return;
current_selection = &seat->pointer_selection; //still need to track the mouse coordinates;
current_selection = &seat->pointer_selection;
}
int x = wl_fixed_to_int(surface_x) + current_selection->current_output->logical_geometry.x;
int y = wl_fixed_to_int(surface_y) + current_selection->current_output->logical_geometry.y;
Expand Down Expand Up @@ -154,8 +153,7 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,

// find smallest box intersecting the cursor
struct slurp_box *box;
wl_list_for_each(box, &seat->state->boxes, link)
{
wl_list_for_each(box, &seat->state->boxes, link) {
if (in_box(box, seat->pointer_selection.x,
seat->pointer_selection.y)) {
if (seat->pointer_selection.has_selection &&
Expand Down Expand Up @@ -213,7 +211,7 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
uint32_t button_state) {
struct slurp_seat *seat = data;
if (seat->touch_selection.has_selection) {
return;
return;
}

seat->button_state = button_state;
Expand Down Expand Up @@ -281,7 +279,7 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard,

case XKB_KEY_space:
if (!seat->pointer_selection.has_selection &&
!seat->touch_selection.has_selection) {
!seat->touch_selection.has_selection) {
break;
}
state->edit_anchor = true;
Expand Down
26 changes: 9 additions & 17 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
#include "render.h"
#include "slurp.h"

static void set_source_u32(cairo_t *cairo, uint32_t color)
{
static void set_source_u32(cairo_t *cairo, uint32_t color) {
cairo_set_source_rgba(cairo, (color >> (3 * 8) & 0xFF) / 255.0,
(color >> (2 * 8) & 0xFF) / 255.0,
(color >> (1 * 8) & 0xFF) / 255.0,
(color >> (0 * 8) & 0xFF) / 255.0);
(color >> (2 * 8) & 0xFF) / 255.0,
(color >> (1 * 8) & 0xFF) / 255.0,
(color >> (0 * 8) & 0xFF) / 255.0);
}

void render(struct slurp_output *output)
{
void render(struct slurp_output *output) {
struct slurp_state *state = output->state;
struct pool_buffer *buffer = output->current_buffer;
cairo_t *cairo = buffer->cairo;
Expand All @@ -27,20 +25,14 @@ void render(struct slurp_output *output)
cairo_paint(cairo);

struct slurp_seat *seat;
wl_list_for_each(seat, &state->seats, link)
{
wl_list_for_each(seat, &state->seats, link) {
struct slurp_selection *current_selection =
seat_get_current_selection(seat);
if (current_selection == NULL)
continue;
if (!seat->wl_pointer)
continue;
if (!current_selection->has_selection) {
seat_get_current_selection(seat);
if (!seat->wl_pointer) {
continue;
}

if (!box_intersect(&output->logical_geometry,
&current_selection->selection)) {
&current_selection->selection)) {
continue;
}
struct slurp_box b = current_selection->selection;
Expand Down

0 comments on commit b03c1bb

Please sign in to comment.