Skip to content
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
4 changes: 3 additions & 1 deletion .build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ packages:
- wayland-protocols
- cairo
- libxkbcommon
# needed for clang-format
- clang
sources:
- https://github.com/emerison/slurp
tasks:
Expand All @@ -13,4 +15,4 @@ tasks:
meson setup build
- build: |
cd slurp
ninja -C build
ninja -C build all clang-format-check
32 changes: 32 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
Language: Cpp
BasedOnStyle: LLVM
AlignAfterOpenBracket: DontAlign
AlignOperands: DontAlign
AllowShortFunctionsOnASingleLine: Empty
AlwaysBreakBeforeMultilineStrings: true
BracedInitializerIndentWidth: 4
BreakBinaryOperations: RespectPrecedence
# At some point, it might make sense to change this, but for now, to minimize
# initial changes allow line breaks where they currently are
ColumnLimit: 0
ContinuationIndentWidth: 8
IndentWidth: 4
InsertBraces: true
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^"slurp.h"'
Priority: 0
SortPriority: 0
- Regex: '^"(box|lock|render|pool-buffer).h"'
Priority: 0
SortPriority: 2
- Regex: '^<'
Priority: -1
InsertNewlineAtEOF: true
LineEnding: LF
PenaltyBreakOpenParenthesis: 50
PenaltyBreakBeforeFirstCallParameter: 900
QualifierAlignment: Left
TabWidth: 4
UseTab: ForContinuationAndIndentation
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ root = true
charset = utf-8
end_of_line = lf
indent_style = tab
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[*.{clang-format,yml}]
indent_style = space
indent_size = 2
14 changes: 7 additions & 7 deletions box.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

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;
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;
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) {
Expand Down
2 changes: 2 additions & 0 deletions include/lock.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _LOCK_H
#define _LOCK_H

#include <stdbool.h>

bool acquire_lock();

#endif
2 changes: 1 addition & 1 deletion include/pool-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct pool_buffer {
};

struct pool_buffer *get_next_buffer(struct wl_shm *shm,
struct pool_buffer pool[static 2], uint32_t width, uint32_t height);
struct pool_buffer pool[static 2], uint32_t width, uint32_t height);
void finish_buffer(struct pool_buffer *buffer);

#endif
157 changes: 79 additions & 78 deletions include/slurp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,116 +6,117 @@
#include <wayland-client.h>

#include "box.h"
#include "cursor-shape-v1-client-protocol.h"
#include "pool-buffer.h"

#include "cursor-shape-v1-client-protocol.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_selection {
struct slurp_output *current_output;
int32_t x, y;
int32_t anchor_x, anchor_y;
struct slurp_box selection;
bool has_selection;
struct slurp_output *current_output;
int32_t x, y;
int32_t anchor_x, anchor_y;
struct slurp_box selection;
bool has_selection;
};

struct slurp_state {
bool running;
bool edit_anchor;

struct wl_display *display;
struct wl_registry *registry;
struct wl_shm *shm;
struct wl_compositor *compositor;
struct zwlr_layer_shell_v1 *layer_shell;
struct zxdg_output_manager_v1 *xdg_output_manager;
struct wp_cursor_shape_manager_v1 *cursor_shape_manager;
struct wl_list outputs; // slurp_output::link
struct wl_list seats; // slurp_seat::link

struct xkb_context *xkb_context;

struct {
uint32_t background;
uint32_t border;
uint32_t selection;
uint32_t choice;
} colors;

const char *font_family;

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

struct slurp_box result;
bool running;
bool edit_anchor;

struct wl_display *display;
struct wl_registry *registry;
struct wl_shm *shm;
struct wl_compositor *compositor;
struct zwlr_layer_shell_v1 *layer_shell;
struct zxdg_output_manager_v1 *xdg_output_manager;
struct wp_cursor_shape_manager_v1 *cursor_shape_manager;
struct wl_list outputs; // slurp_output::link
struct wl_list seats; // slurp_seat::link

struct xkb_context *xkb_context;

struct {
uint32_t background;
uint32_t border;
uint32_t selection;
uint32_t choice;
} colors;

const char *font_family;

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

struct slurp_box result;
};

struct slurp_output {
struct wl_output *wl_output;
struct slurp_state *state;
struct wl_list link; // slurp_state::outputs
struct wl_output *wl_output;
struct slurp_state *state;
struct wl_list link; // slurp_state::outputs

struct slurp_box geometry;
struct slurp_box logical_geometry;
int32_t scale;
struct slurp_box geometry;
struct slurp_box logical_geometry;
int32_t scale;

struct wl_surface *surface;
struct zwlr_layer_surface_v1 *layer_surface;
struct wl_surface *surface;
struct zwlr_layer_surface_v1 *layer_surface;

struct zxdg_output_v1 *xdg_output;
struct zxdg_output_v1 *xdg_output;

struct wl_callback *frame_callback;
bool configured;
bool dirty;
int32_t width, height;
struct pool_buffer buffers[2];
struct pool_buffer *current_buffer;
struct wl_callback *frame_callback;
bool configured;
bool dirty;
int32_t width, height;
struct pool_buffer buffers[2];
struct pool_buffer *current_buffer;

struct wl_cursor_theme *cursor_theme;
struct wl_cursor_image *cursor_image;
struct wl_cursor_theme *cursor_theme;
struct wl_cursor_image *cursor_image;
};

struct slurp_seat {
struct wl_surface *cursor_surface;
struct slurp_state *state;
struct wl_seat *wl_seat;
struct wl_list link; // slurp_state::seats
struct wl_surface *cursor_surface;
struct slurp_state *state;
struct wl_seat *wl_seat;
struct wl_list link; // slurp_state::seats

// keyboard:
struct wl_keyboard *wl_keyboard;
// keyboard:
struct wl_keyboard *wl_keyboard;

// selection (pointer/touch):
// selection (pointer/touch):

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;
enum wl_pointer_button_state button_state;
// pointer:
struct wl_pointer *wl_pointer;
enum wl_pointer_button_state button_state;

// keymap:
struct xkb_keymap *xkb_keymap;
struct xkb_state *xkb_state;
// keymap:
struct xkb_keymap *xkb_keymap;
struct xkb_state *xkb_state;

// touch:
struct wl_touch *wl_touch;
int32_t touch_id;
// touch:
struct wl_touch *wl_touch;
int32_t touch_id;
};

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;
return seat->touch_selection.has_selection ? &seat->touch_selection
: &seat->pointer_selection;
}
#endif
7 changes: 2 additions & 5 deletions lock.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/file.h>
Expand Down Expand Up @@ -41,16 +40,14 @@ bool acquire_lock() {
return false;
}
// Open the lock file for write, creating with user read/write if necessary
int fd = open(lockfile, O_WRONLY|O_CREAT, 00600);
int fd = open(lockfile, O_WRONLY | O_CREAT, 00600);
if (fd == -1) {
fprintf(stderr, "failed to open lock file\n");
return false;
}
if (flock(fd, LOCK_EX|LOCK_NB)) {
if (flock(fd, LOCK_EX | LOCK_NB)) {
fprintf(stderr, "another slurp process is running for this wayland session\n");
return false;
}
return true;
}


Loading