diff --git a/config.conf b/config.conf index 923a32f..fab133a 100644 --- a/config.conf +++ b/config.conf @@ -52,6 +52,7 @@ focus_cross_tag=1 enable_floating_snap=0 snap_distance=30 cursor_size=24 +drag_tile_to_tile=1 # keyboard repeat_rate=25 diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 87bcf63..6cb7406 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -122,6 +122,7 @@ typedef struct { int no_border_when_single; int snap_distance; int enable_floating_snap; + int drag_tile_to_tile; unsigned int swipe_min_threshold; float *scroller_proportion_preset; int scroller_proportion_preset_count; @@ -766,6 +767,8 @@ void parse_config_line(Config *config, const char *line) { config->snap_distance = atoi(value); } else if (strcmp(key, "enable_floating_snap") == 0) { 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) { config->swipe_min_threshold = atoi(value); } else if (strcmp(key, "scroller_proportion_preset") == 0) { @@ -1716,6 +1719,7 @@ void override_config(void) { focus_cross_tag = config.focus_cross_tag; no_border_when_single = config.no_border_when_single; snap_distance = config.snap_distance; + drag_tile_to_tile = config.drag_tile_to_tile; enable_floating_snap = config.enable_floating_snap; swipe_min_threshold = config.swipe_min_threshold; scroller_prefer_center = config.scroller_prefer_center; @@ -1816,6 +1820,7 @@ void set_value_default() { config.focus_cross_tag = focus_cross_tag; config.no_border_when_single = no_border_when_single; config.snap_distance = snap_distance; + config.drag_tile_to_tile = drag_tile_to_tile; config.enable_floating_snap = enable_floating_snap; config.swipe_min_threshold = swipe_min_threshold; diff --git a/src/config/preset_config.h b/src/config/preset_config.h index ca12760..9cc7011 100644 --- a/src/config/preset_config.h +++ b/src/config/preset_config.h @@ -57,6 +57,7 @@ int focus_cross_tag = 0; int no_border_when_single = 0; int snap_distance = 30; int enable_floating_snap = 0; +int drag_tile_to_tile = 0; unsigned int cursor_size = 24; unsigned int cursor_hide_timeout = 0; diff --git a/src/maomao.c b/src/maomao.c index 9d4f13d..86becfe 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -272,6 +272,7 @@ struct Client { pid_t pid; Client *swallowing, *swallowedby; bool is_clip_to_hide; + bool drag_to_tile; }; typedef struct { @@ -2537,12 +2538,41 @@ void hold_end(struct wl_listener *listener, void *data) { 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 // 鼠标按键事件 buttonpress(struct wl_listener *listener, void *data) { struct wlr_pointer_button_event *event = data; struct wlr_keyboard *keyboard; uint32_t mods; Client *c; + Client *tmpc; int ji; const MouseBinding *b; struct wlr_surface *surface; @@ -2605,8 +2635,14 @@ buttonpress(struct wl_listener *listener, void *data) { reset_foreign_tolevel(grabc); selmon->prevsel = selmon->sel; selmon->sel = grabc; - apply_window_snap(grabc); + tmpc = grabc; 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; } else { cursor_mode = CurNormal; @@ -4357,6 +4393,7 @@ mapnotify(struct wl_listener *listener, void *data) { c->need_output_flush = 0; c->scroller_proportion = scroller_default_proportion; c->is_open_animation = true; + c->drag_to_tile = false; if (new_is_master && 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 */ if (grabc->isfloating == 0) { + grabc->drag_to_tile = true; setfloating(grabc, 1); }