mirror of
https://codeberg.org/vyivel/dulcepan/
synced 2025-03-12 18:59:15 +02:00
206 lines
4.4 KiB
C
206 lines
4.4 KiB
C
#ifndef DULCEPAN_H
|
|
#define DULCEPAN_H
|
|
|
|
#include <cairo.h>
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <wayland-util.h>
|
|
#include <xkbcommon/xkbcommon.h>
|
|
|
|
// Per-output
|
|
#define DP_SWAPCHAIN_LEN 2
|
|
|
|
enum dp_status {
|
|
DP_STATUS_RUNNING,
|
|
DP_STATUS_SAVED,
|
|
DP_STATUS_QUIT,
|
|
};
|
|
|
|
struct dp_buffer {
|
|
struct wl_buffer *wl_buffer;
|
|
cairo_t *cairo;
|
|
cairo_surface_t *cairo_surface;
|
|
void *data;
|
|
size_t size;
|
|
bool used;
|
|
};
|
|
|
|
struct dp_output {
|
|
struct dp_state *state;
|
|
|
|
uint32_t global_name;
|
|
struct wl_output *wl_output;
|
|
|
|
struct wl_surface *main_surface;
|
|
struct zwlr_layer_surface_v1 *main_layer_surface;
|
|
struct wp_viewport *main_viewport;
|
|
|
|
struct wl_surface *select_surface;
|
|
struct wl_subsurface *select_subsurface;
|
|
struct wp_viewport *select_viewport;
|
|
|
|
int width, height;
|
|
int32_t transform;
|
|
bool has_geom;
|
|
int transformed_width, transformed_height;
|
|
|
|
int effective_width, effective_height;
|
|
bool initialized;
|
|
|
|
double scale;
|
|
|
|
struct wl_callback *redraw_callback;
|
|
bool needs_redraw;
|
|
|
|
struct zwlr_screencopy_frame_v1 *frame;
|
|
bool has_frame;
|
|
// XXX: this is completely untested
|
|
bool y_invert;
|
|
|
|
struct wl_buffer *frame_buffer;
|
|
int32_t frame_stride;
|
|
uint32_t frame_format;
|
|
void *frame_data;
|
|
size_t frame_size;
|
|
|
|
struct dp_buffer swapchain[DP_SWAPCHAIN_LEN];
|
|
|
|
struct wl_list link;
|
|
};
|
|
|
|
struct dp_seat {
|
|
struct dp_state *state;
|
|
|
|
uint32_t global_name;
|
|
struct wl_seat *wl_seat;
|
|
|
|
struct wl_keyboard *keyboard;
|
|
struct wl_pointer *pointer;
|
|
|
|
struct xkb_keymap *xkb_keymap;
|
|
struct xkb_state *xkb_state;
|
|
|
|
struct wp_cursor_shape_device_v1 *cursor_shape_device;
|
|
|
|
// The output the pointer is on
|
|
struct dp_output *ptr_output;
|
|
// In buffer space
|
|
int ptr_x, ptr_y;
|
|
|
|
struct wl_list link;
|
|
};
|
|
|
|
enum dp_selection_action {
|
|
DP_SELECTION_ACTION_NONE,
|
|
DP_SELECTION_ACTION_RESIZING,
|
|
DP_SELECTION_ACTION_MOVING,
|
|
};
|
|
|
|
enum dp_resize_edges {
|
|
DP_EDGE_NONE = 0,
|
|
|
|
DP_EDGE_TOP = 1 << 0,
|
|
DP_EDGE_BOTTOM = 1 << 1,
|
|
DP_EDGE_LEFT = 1 << 2,
|
|
DP_EDGE_RIGHT = 1 << 3,
|
|
};
|
|
|
|
struct dp_selection {
|
|
struct dp_output *output; // May be NULL
|
|
int x, y, width, height;
|
|
|
|
enum dp_selection_action action;
|
|
bool action_active;
|
|
// Pointer offset to apply during movement
|
|
int ptr_off_x, ptr_off_y;
|
|
int resize_edges;
|
|
// Resize anchor
|
|
int resize_x, resize_y;
|
|
};
|
|
|
|
enum dp_file_format {
|
|
DP_FILE_UNKNOWN = 0,
|
|
|
|
DP_FILE_PNG,
|
|
DP_FILE_PPM,
|
|
};
|
|
|
|
struct dp_config {
|
|
// RGBA, not premultiplied
|
|
float unselected_color[4];
|
|
float selected_color[4];
|
|
float border_color[4];
|
|
xkb_keysym_t quit_key;
|
|
xkb_keysym_t save_key;
|
|
int border_size; // 0 if disabled
|
|
int png_compression;
|
|
bool quick_select;
|
|
};
|
|
|
|
struct dp_state {
|
|
enum dp_status status;
|
|
|
|
struct wl_display *display;
|
|
struct wl_registry *registry;
|
|
|
|
struct wl_compositor *compositor;
|
|
struct wl_subcompositor *subcompositor;
|
|
struct wp_viewporter *viewporter;
|
|
struct wl_shm *shm;
|
|
struct zwlr_layer_shell_v1 *layer_shell;
|
|
struct zwlr_screencopy_manager_v1 *screencopy_manager;
|
|
struct wp_cursor_shape_manager_v1 *cursor_shape_manager;
|
|
|
|
bool initialized;
|
|
|
|
struct xkb_context *xkb_context;
|
|
|
|
struct wl_list outputs;
|
|
struct wl_list seats;
|
|
|
|
struct dp_selection selection;
|
|
|
|
struct dp_config config;
|
|
const char *output_path; // May be NULL
|
|
enum dp_file_format output_format;
|
|
|
|
bool show_cursors;
|
|
};
|
|
|
|
void dp_config_load(struct dp_config *config, const char *user_path);
|
|
|
|
// When done, data must be unmapped
|
|
struct wl_buffer *dp_buffer_create(struct dp_state *state, int32_t width, int32_t height,
|
|
int32_t stride, uint32_t format, void **data, size_t *size);
|
|
|
|
void dp_output_create(struct dp_state *state, uint32_t name, struct wl_output *wl_output);
|
|
void dp_output_destroy(struct dp_output *output);
|
|
|
|
void dp_output_redraw(struct dp_output *output);
|
|
|
|
void dp_output_hide_surface(struct dp_output *output);
|
|
|
|
void dp_seat_create(struct dp_state *state, uint32_t name, struct wl_seat *wl_seat);
|
|
void dp_seat_destroy(struct dp_seat *seat);
|
|
|
|
void dp_select_start_interactive(struct dp_selection *selection, struct dp_output *output, int x,
|
|
int y, bool modify_existing);
|
|
void dp_select_stop_interactive(struct dp_selection *selection);
|
|
|
|
void dp_select_notify_pointer_position(
|
|
struct dp_selection *selection, struct dp_output *output, int x, int y);
|
|
|
|
void dp_select_whole(struct dp_selection *selection, struct dp_output *output);
|
|
|
|
void dp_save(struct dp_state *state);
|
|
|
|
void dp_log_error(const char *fmt, ...);
|
|
void dp_log_fatal(const char *fmt, ...);
|
|
|
|
void *dp_zalloc(size_t size);
|
|
|
|
const char *dp_ext_from_path(const char *path);
|
|
enum dp_file_format dp_ext_to_format(const char *ext);
|
|
|
|
#endif
|