feat: add option drag_tile_to_tile

This commit is contained in:
DreamMaoMao 2025-05-14 19:38:34 +08:00
parent b0082b1fb8
commit 94f502915e
4 changed files with 46 additions and 1 deletions

View file

@ -52,6 +52,7 @@ focus_cross_tag=1
enable_floating_snap=0 enable_floating_snap=0
snap_distance=30 snap_distance=30
cursor_size=24 cursor_size=24
drag_tile_to_tile=1
# keyboard # keyboard
repeat_rate=25 repeat_rate=25

View file

@ -122,6 +122,7 @@ typedef struct {
int no_border_when_single; int no_border_when_single;
int snap_distance; int snap_distance;
int enable_floating_snap; int enable_floating_snap;
int drag_tile_to_tile;
unsigned int swipe_min_threshold; unsigned int swipe_min_threshold;
float *scroller_proportion_preset; float *scroller_proportion_preset;
int scroller_proportion_preset_count; int scroller_proportion_preset_count;
@ -766,6 +767,8 @@ void parse_config_line(Config *config, const char *line) {
config->snap_distance = atoi(value); config->snap_distance = atoi(value);
} else if (strcmp(key, "enable_floating_snap") == 0) { } else if (strcmp(key, "enable_floating_snap") == 0) {
config->enable_floating_snap = atoi(value); config->enable_floating_snap = atoi(value);
} else if (strcmp(key, "drag_tile_to_tile") == 0) {
config->drag_tile_to_tile = atoi(value);
} else if (strcmp(key, "swipe_min_threshold") == 0) { } else if (strcmp(key, "swipe_min_threshold") == 0) {
config->swipe_min_threshold = atoi(value); config->swipe_min_threshold = atoi(value);
} else if (strcmp(key, "scroller_proportion_preset") == 0) { } else if (strcmp(key, "scroller_proportion_preset") == 0) {
@ -1716,6 +1719,7 @@ void override_config(void) {
focus_cross_tag = config.focus_cross_tag; focus_cross_tag = config.focus_cross_tag;
no_border_when_single = config.no_border_when_single; no_border_when_single = config.no_border_when_single;
snap_distance = config.snap_distance; snap_distance = config.snap_distance;
drag_tile_to_tile = config.drag_tile_to_tile;
enable_floating_snap = config.enable_floating_snap; enable_floating_snap = config.enable_floating_snap;
swipe_min_threshold = config.swipe_min_threshold; swipe_min_threshold = config.swipe_min_threshold;
scroller_prefer_center = config.scroller_prefer_center; scroller_prefer_center = config.scroller_prefer_center;
@ -1816,6 +1820,7 @@ void set_value_default() {
config.focus_cross_tag = focus_cross_tag; config.focus_cross_tag = focus_cross_tag;
config.no_border_when_single = no_border_when_single; config.no_border_when_single = no_border_when_single;
config.snap_distance = snap_distance; config.snap_distance = snap_distance;
config.drag_tile_to_tile = drag_tile_to_tile;
config.enable_floating_snap = enable_floating_snap; config.enable_floating_snap = enable_floating_snap;
config.swipe_min_threshold = swipe_min_threshold; config.swipe_min_threshold = swipe_min_threshold;

View file

@ -57,6 +57,7 @@ int focus_cross_tag = 0;
int no_border_when_single = 0; int no_border_when_single = 0;
int snap_distance = 30; int snap_distance = 30;
int enable_floating_snap = 0; int enable_floating_snap = 0;
int drag_tile_to_tile = 0;
unsigned int cursor_size = 24; unsigned int cursor_size = 24;
unsigned int cursor_hide_timeout = 0; unsigned int cursor_hide_timeout = 0;

View file

@ -272,6 +272,7 @@ struct Client {
pid_t pid; pid_t pid;
Client *swallowing, *swallowedby; Client *swallowing, *swallowedby;
bool is_clip_to_hide; bool is_clip_to_hide;
bool drag_to_tile;
}; };
typedef struct { typedef struct {
@ -2537,12 +2538,41 @@ void hold_end(struct wl_listener *listener, void *data) {
event->time_msec, event->cancelled); event->time_msec, event->cancelled);
} }
void place_drag_tile_client(Client *c) {
Client *tc = NULL;
Client *closest_client = NULL;
long min_distant = LONG_MAX;
long temp_distant;
unsigned int x,y;
wl_list_for_each(tc, &clients, link) {
if (tc != c && ISTILED(tc) && VISIBLEON(tc, c->mon)) {
x = tc->geom.x + tc->geom.width / 2 - cursor->x;
y = tc->geom.y + tc->geom.height / 2 - cursor->y;
temp_distant = x * x + y * y;
if (temp_distant < min_distant) {
min_distant = temp_distant;
closest_client = tc;
}
}
}
if(closest_client) {
wl_list_remove(&c->link);
c->link.next = &closest_client->link;
c->link.prev = closest_client->link.prev;
closest_client->link.prev->next = &c->link;
closest_client->link.prev = &c->link;
}
setfloating(c, 0);
}
void // 鼠标按键事件 void // 鼠标按键事件
buttonpress(struct wl_listener *listener, void *data) { buttonpress(struct wl_listener *listener, void *data) {
struct wlr_pointer_button_event *event = data; struct wlr_pointer_button_event *event = data;
struct wlr_keyboard *keyboard; struct wlr_keyboard *keyboard;
uint32_t mods; uint32_t mods;
Client *c; Client *c;
Client *tmpc;
int ji; int ji;
const MouseBinding *b; const MouseBinding *b;
struct wlr_surface *surface; struct wlr_surface *surface;
@ -2605,8 +2635,14 @@ buttonpress(struct wl_listener *listener, void *data) {
reset_foreign_tolevel(grabc); reset_foreign_tolevel(grabc);
selmon->prevsel = selmon->sel; selmon->prevsel = selmon->sel;
selmon->sel = grabc; selmon->sel = grabc;
apply_window_snap(grabc); tmpc = grabc;
grabc = NULL; grabc = NULL;
if(tmpc->drag_to_tile && drag_tile_to_tile){
place_drag_tile_client(tmpc);
} else {
apply_window_snap(tmpc);
}
tmpc->drag_to_tile = false;
return; return;
} else { } else {
cursor_mode = CurNormal; cursor_mode = CurNormal;
@ -4357,6 +4393,7 @@ mapnotify(struct wl_listener *listener, void *data) {
c->need_output_flush = 0; c->need_output_flush = 0;
c->scroller_proportion = scroller_default_proportion; c->scroller_proportion = scroller_default_proportion;
c->is_open_animation = true; c->is_open_animation = true;
c->drag_to_tile = false;
if (new_is_master && if (new_is_master &&
strcmp(selmon->pertag->ltidxs[selmon->pertag->curtag]->name, strcmp(selmon->pertag->ltidxs[selmon->pertag->curtag]->name,
@ -4628,6 +4665,7 @@ moveresize(const Arg *arg) {
/* Float the window and tell motionnotify to grab it */ /* Float the window and tell motionnotify to grab it */
if (grabc->isfloating == 0) { if (grabc->isfloating == 0) {
grabc->drag_to_tile = true;
setfloating(grabc, 1); setfloating(grabc, 1);
} }