Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use keyboard selection #116

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions box.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "box.h"

bool box_intersect(const struct slurp_box *a, const struct slurp_box *b) {
return a->x < b->x + b->width &&
a->x + a->width > b->x &&
a->y < b->y + b->height &&
a->height + a->y > b->y;
}

bool in_box(const struct slurp_box *box, int32_t x, int32_t y) {
return box->x <= x
&& box->x + box->width > x
&& box->y <= y
&& box->y + box->height > y;
}

int32_t box_size(const struct slurp_box *box) {
return box->width * box->height;
}
21 changes: 21 additions & 0 deletions include/box.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef _BOX_H
#define _BOX_H

#include <stdbool.h>
#include <stdint.h>
#include <wayland-client.h>

struct slurp_box {
int32_t x, y;
int32_t width, height;
char *label;
struct wl_list link;
};

bool box_intersect(const struct slurp_box *a, const struct slurp_box *b);

bool in_box(const struct slurp_box *box, int32_t x, int32_t y);

int32_t box_size(const struct slurp_box *box);

#endif
18 changes: 10 additions & 8 deletions include/slurp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@
#include <stdint.h>
#include <wayland-client.h>

#include "box.h"
#include "pool-buffer.h"
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
#include "xdg-output-unstable-v1-client-protocol.h"

#define TOUCH_ID_EMPTY -1

struct slurp_box {
int32_t x, y;
int32_t width, height;
char *label;
struct wl_list link;
};

struct slurp_selection {
struct slurp_output *current_output;
int32_t x, y;
Expand Down Expand Up @@ -46,16 +40,22 @@ struct slurp_state {
uint32_t border;
uint32_t selection;
uint32_t choice;
uint32_t font;
uint32_t choice_font;
uint32_t crosshair;
} colors;

const char *font_family;
uint32_t font_size;

uint32_t border_weight;
bool display_dimensions;
bool display_labels;
bool single_point;
bool restrict_selection;
struct wl_list boxes; // slurp_box::link
bool fixed_aspect_ratio;
bool crosshair;
double aspect_ratio; // h / w

struct slurp_box result;
Expand Down Expand Up @@ -99,6 +99,7 @@ struct slurp_seat {

struct slurp_selection pointer_selection;
struct slurp_selection touch_selection;
struct slurp_selection keyboard_selection;

// pointer:
struct wl_pointer *wl_pointer;
Expand All @@ -118,6 +119,7 @@ bool box_intersect(const struct slurp_box *a, const struct slurp_box *b);
static inline struct slurp_selection *slurp_seat_current_selection(struct slurp_seat *seat) {
return seat->touch_selection.has_selection ?
&seat->touch_selection :
&seat->pointer_selection;
seat->keyboard_selection.has_selection ?
&seat->keyboard_selection : &seat->pointer_selection;
}
#endif
Loading