1
0
mirror of https://codeberg.org/vyivel/dulcepan/ synced 2025-06-24 22:44:18 +03:00

1 Commits

Author SHA1 Message Date
3189f7c769 config: Enter => Return 2025-04-22 10:13:39 +03:00
5 changed files with 40 additions and 60 deletions

View File

@ -33,10 +33,6 @@ animation-duration = 0
# or when a whole output is selected with a mouse button. # or when a whole output is selected with a mouse button.
quick-select = false quick-select = false
# If true, dulcepan will allow editing the current selection if quick-select is
# true. Has no effect if quick-select is false.
quick-select-allow-editing = true
# If true, dulcepan will remember selection between runs. # If true, dulcepan will remember selection between runs.
# The state is stored at $XDG_CACHE_HOME/dulcepan. # The state is stored at $XDG_CACHE_HOME/dulcepan.
persistence = true persistence = true
@ -47,4 +43,4 @@ png-compression = 6
# Key bindings. Each binding is a comma-separated list of key names; empty names # Key bindings. Each binding is a comma-separated list of key names; empty names
# are ignored. A binding may be empty. # are ignored. A binding may be empty.
quit-key = Escape quit-key = Escape
save-key = Space,Enter save-key = Space,Return

View File

@ -125,7 +125,6 @@ void dp_config_load(struct dp_state *state, const char *user_path) {
.animation_duration = 0, .animation_duration = 0,
.png_compression = 6, .png_compression = 6,
.quick_select = false, .quick_select = false,
.quick_select_allow_editing = true,
.persistence = true, .persistence = true,
}; };
@ -244,8 +243,6 @@ void dp_config_load(struct dp_state *state, const char *user_path) {
load_int(value, line_idx, 0, 9, &config->png_compression); load_int(value, line_idx, 0, 9, &config->png_compression);
} else if (strcmp(key, "quick-select") == 0) { } else if (strcmp(key, "quick-select") == 0) {
load_bool(value, line_idx, &config->quick_select); load_bool(value, line_idx, &config->quick_select);
} else if (strcmp(key, "quick-select-allow-editing") == 0) {
load_bool(value, line_idx, &config->quick_select_allow_editing);
} else if (strcmp(key, "persistence") == 0) { } else if (strcmp(key, "persistence") == 0) {
load_bool(value, line_idx, &config->persistence); load_bool(value, line_idx, &config->persistence);
} else if (strcmp(key, "quit-key") == 0) { } else if (strcmp(key, "quit-key") == 0) {

View File

@ -171,10 +171,7 @@ struct dp_config {
int animation_duration; // In milliseconds int animation_duration; // In milliseconds
int png_compression; int png_compression;
bool quick_select; bool quick_select;
bool quick_select_allow_editing;
bool persistence; bool persistence;
}; };
@ -211,8 +208,6 @@ struct dp_state {
const char *output_path; // May be NULL const char *output_path; // May be NULL
enum dp_file_format output_format; enum dp_file_format output_format;
bool allow_selection_editing;
bool show_cursors; bool show_cursors;
cairo_pattern_t *border_pattern; cairo_pattern_t *border_pattern;

View File

@ -248,9 +248,6 @@ int main(int argc, char **argv) {
state.xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); state.xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
struct dp_config *config = &state.config; struct dp_config *config = &state.config;
state.allow_selection_editing = !config->quick_select || config->quick_select_allow_editing;
if (config->border_gradient != DP_BORDER_GRADIENT_NONE) { if (config->border_gradient != DP_BORDER_GRADIENT_NONE) {
state.border_pattern = cairo_pattern_create_linear(0, 0, 1, 0); state.border_pattern = cairo_pattern_create_linear(0, 0, 1, 0);
cairo_pattern_add_color_stop_rgba(state.border_pattern, 0, config->border_color[0], cairo_pattern_add_color_stop_rgba(state.border_pattern, 0, config->border_color[0],

View File

@ -92,55 +92,51 @@ static const struct wl_keyboard_listener keyboard_listener = {
.modifiers = keyboard_handle_modifiers, .modifiers = keyboard_handle_modifiers,
}; };
static enum wp_cursor_shape_device_v1_shape get_cursor_shape(struct dp_state *state) { static enum wp_cursor_shape_device_v1_shape get_cursor_shape(struct dp_selection *selection) {
if (state->allow_selection_editing) { switch (selection->action) {
struct dp_selection *selection = &state->selection; case DP_SELECTION_ACTION_NONE:
switch (selection->action) { break;
case DP_SELECTION_ACTION_NONE: case DP_SELECTION_ACTION_RESIZING:
if (selection->width == 0 || selection->height == 0) {
break; break;
case DP_SELECTION_ACTION_RESIZING:
if (selection->width == 0 || selection->height == 0) {
break;
}
switch (selection->resize_edges) {
case DP_EDGE_TOP:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_N_RESIZE;
case DP_EDGE_TOP | DP_EDGE_LEFT:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NW_RESIZE;
case DP_EDGE_TOP | DP_EDGE_RIGHT:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NE_RESIZE;
case DP_EDGE_BOTTOM:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_S_RESIZE;
case DP_EDGE_BOTTOM | DP_EDGE_LEFT:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_SW_RESIZE;
case DP_EDGE_BOTTOM | DP_EDGE_RIGHT:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_SE_RESIZE;
case DP_EDGE_LEFT:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_W_RESIZE;
case DP_EDGE_RIGHT:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_E_RESIZE;
}
break;
case DP_SELECTION_ACTION_MOVING:
// XXX: this might have rounding issues but whatever
if (selection->x == 0 && selection->y == 0 &&
selection->width == selection->output->effective_width &&
selection->height == selection->output->effective_height) {
// Moving is impossible
break;
}
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_MOVE;
} }
switch (selection->resize_edges) {
case DP_EDGE_TOP:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_N_RESIZE;
case DP_EDGE_TOP | DP_EDGE_LEFT:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NW_RESIZE;
case DP_EDGE_TOP | DP_EDGE_RIGHT:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NE_RESIZE;
case DP_EDGE_BOTTOM:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_S_RESIZE;
case DP_EDGE_BOTTOM | DP_EDGE_LEFT:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_SW_RESIZE;
case DP_EDGE_BOTTOM | DP_EDGE_RIGHT:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_SE_RESIZE;
case DP_EDGE_LEFT:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_W_RESIZE;
case DP_EDGE_RIGHT:
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_E_RESIZE;
}
break;
case DP_SELECTION_ACTION_MOVING:
// XXX: this might have rounding issues but whatever
if (selection->x == 0 && selection->y == 0 &&
selection->width == selection->output->effective_width &&
selection->height == selection->output->effective_height) {
// Moving is impossible
break;
}
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_MOVE;
} }
// The default cursor // The default cursor
return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CROSSHAIR; return WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CROSSHAIR;
} }
static void update_cursor(struct dp_seat *seat) { static void update_cursor(struct dp_seat *seat) {
if (seat->cursor_shape_device != NULL) { if (seat->cursor_shape_device != NULL) {
wp_cursor_shape_device_v1_set_shape( wp_cursor_shape_device_v1_set_shape(seat->cursor_shape_device, seat->pointer_serial,
seat->cursor_shape_device, seat->pointer_serial, get_cursor_shape(seat->state)); get_cursor_shape(&seat->state->selection));
} }
} }
@ -186,8 +182,7 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, uin
struct dp_selection *selection = &state->selection; struct dp_selection *selection = &state->selection;
if (button_state != WL_POINTER_BUTTON_STATE_PRESSED) { if (button_state != WL_POINTER_BUTTON_STATE_PRESSED) {
if (selection->action == DP_SELECTION_ACTION_RESIZING && selection->width > 0 && if (selection->width > 0 && selection->height > 0 && state->config.quick_select) {
selection->height > 0 && state->config.quick_select) {
state->status = DP_STATUS_SAVED; state->status = DP_STATUS_SAVED;
} }
dp_select_stop_interactive(selection); dp_select_stop_interactive(selection);
@ -201,8 +196,8 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, uin
switch (button) { switch (button) {
case BTN_LEFT: case BTN_LEFT:
case BTN_RIGHT: case BTN_RIGHT:
dp_select_start_interactive(selection, seat->ptr_output, seat->ptr_x, seat->ptr_y, dp_select_start_interactive(
state->allow_selection_editing && button == BTN_LEFT); selection, seat->ptr_output, seat->ptr_x, seat->ptr_y, button == BTN_LEFT);
update_cursor(seat); update_cursor(seat);
break; break;
case BTN_MIDDLE: case BTN_MIDDLE: