Compare commits
2 Commits
5e22aed718
...
049b18a496
| Author | SHA1 | Date | |
|---|---|---|---|
|
049b18a496
|
|||
|
ced78b004f
|
16
src/action.c
16
src/action.c
@@ -36,20 +36,10 @@ void send_client_to_tag(const user_action_arg_t *arg) {
|
||||
void send_client_to_next_monitor(const user_action_arg_t *arg) {
|
||||
if (!wm.client_focused) return;
|
||||
|
||||
monitor_t *current_monitor = wm.client_focused->monitor;
|
||||
monitor_t *next_monitor = current_monitor->next;
|
||||
if (next_monitor == nullptr) {
|
||||
next_monitor = wm.monitor_list;
|
||||
} else {
|
||||
for (monitor_t *m = wm.monitor_list; m && m->next != current_monitor;
|
||||
m = m->next) {
|
||||
next_monitor = m;
|
||||
}
|
||||
}
|
||||
monitor_t *next_monitor = wm_get_next_monitor(wm.client_focused->monitor);
|
||||
if (wm.client_focused->monitor == next_monitor) return;
|
||||
|
||||
if (current_monitor != next_monitor) {
|
||||
client_send_to_monitor(wm.client_focused, next_monitor);
|
||||
}
|
||||
client_send_to_monitor(wm.client_focused, next_monitor);
|
||||
}
|
||||
|
||||
void spawn(const user_action_arg_t *arg) {
|
||||
|
||||
@@ -11,3 +11,7 @@ typedef struct extent_in_bar_t {
|
||||
int16_t start;
|
||||
int16_t end;
|
||||
} extent_in_bar_t;
|
||||
|
||||
typedef struct point_t {
|
||||
int16_t x, y;
|
||||
} point_t;
|
||||
|
||||
@@ -251,6 +251,7 @@ void client_send_to_monitor(client_t *client, monitor_t *monitor) {
|
||||
client->tags = monitor->selected_tag->mask;
|
||||
client_add_to_tag(client, monitor->selected_tag);
|
||||
|
||||
wm.current_monitor = monitor;
|
||||
monitor_arrange(m);
|
||||
monitor_arrange(monitor);
|
||||
monitor_draw_bar(m);
|
||||
|
||||
@@ -285,3 +285,21 @@ void monitor_arrange(monitor_t *monitor) {
|
||||
}
|
||||
xcb_flush(wm.xcb_conn);
|
||||
}
|
||||
|
||||
void monitor_save_cursor_point(monitor_t *monitor) {
|
||||
monitor->cursor_position = xcursor_query_pointer_position();
|
||||
monitor->position_inited = true;
|
||||
}
|
||||
|
||||
void monitor_restore_cursor_point(monitor_t *monitor) {
|
||||
if (monitor->position_inited) {
|
||||
xcursor_set_pointer_position(monitor->cursor_position);
|
||||
return;
|
||||
}
|
||||
|
||||
point_t point = xcursor_query_pointer_position();
|
||||
monitor_t *m = wm_get_monitor_by_point(point);
|
||||
monitor->cursor_position.x = point.x - m->geometry.x + monitor->geometry.x;
|
||||
monitor->cursor_position.y = point.y - m->geometry.y + monitor->geometry.y;
|
||||
monitor->position_inited = true;
|
||||
}
|
||||
|
||||
@@ -12,3 +12,5 @@ void monitor_clean(monitor_t *monitor);
|
||||
void monitor_init_bar(monitor_t *monitor);
|
||||
void monitor_draw_bar(monitor_t *monitor);
|
||||
void monitor_arrange(monitor_t *monitor);
|
||||
void monitor_save_cursor_point(monitor_t *monitor);
|
||||
void monitor_restore_cursor_point(monitor_t *monitor);
|
||||
|
||||
@@ -61,6 +61,9 @@ struct monitor_t {
|
||||
extent_in_bar_t layout_symbol_extent;
|
||||
|
||||
xcb_window_t bar_window;
|
||||
|
||||
point_t cursor_position;
|
||||
bool position_inited;
|
||||
};
|
||||
|
||||
struct tag_t {
|
||||
|
||||
16
src/wm.c
16
src/wm.c
@@ -409,6 +409,22 @@ void wm_restack_clients(void) {
|
||||
xcb_flush(wm.xcb_conn);
|
||||
}
|
||||
|
||||
monitor_t *wm_get_monitor_by_point(point_t point) {
|
||||
for (monitor_t *m = wm.monitor_list; m; m = m->next) {
|
||||
if (m->geometry.x <= point.x &&
|
||||
point.x < m->geometry.x + m->geometry.width) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return wm.monitor_list;
|
||||
}
|
||||
|
||||
monitor_t *wm_get_next_monitor(monitor_t *monitor) {
|
||||
monitor_t *next_monitor = monitor->next;
|
||||
if (next_monitor == nullptr) next_monitor = wm.monitor_list;
|
||||
return next_monitor;
|
||||
}
|
||||
|
||||
static void debug_show_monitor_list(void) {
|
||||
logger("\n========================== monitors ==========================\n");
|
||||
for (monitor_t *m = wm.monitor_list; m; m = m->next) {
|
||||
|
||||
3
src/wm.h
3
src/wm.h
@@ -5,6 +5,7 @@
|
||||
#include <xcb/xcb_xrm.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
|
||||
#include "base.h"
|
||||
#include "types.h"
|
||||
|
||||
typedef struct wm_t {
|
||||
@@ -52,3 +53,5 @@ extern wm_t wm;
|
||||
void wm_restart(void);
|
||||
void wm_quit(void);
|
||||
void wm_restack_clients(void);
|
||||
monitor_t *wm_get_monitor_by_point(point_t point);
|
||||
monitor_t *wm_get_next_monitor(monitor_t *monitor);
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <xcb/xcb_cursor.h>
|
||||
#include <xcb/xproto.h>
|
||||
|
||||
#include "base.h"
|
||||
#include "utils.h"
|
||||
#include "wm.h"
|
||||
|
||||
@@ -126,3 +128,19 @@ void xcursor_clean(void) {
|
||||
}
|
||||
if (cursor_ctx) xcb_cursor_context_free(cursor_ctx);
|
||||
}
|
||||
|
||||
point_t xcursor_query_pointer_position(void) {
|
||||
xcb_query_pointer_cookie_t cookie =
|
||||
xcb_query_pointer(wm.xcb_conn, wm.screen->root);
|
||||
xcb_query_pointer_reply_t *reply =
|
||||
xcb_query_pointer_reply(wm.xcb_conn, cookie, nullptr);
|
||||
point_t pos = {.x = reply->root_x, .y = reply->root_y};
|
||||
p_delete(&reply);
|
||||
return pos;
|
||||
}
|
||||
|
||||
void xcursor_set_pointer_position(point_t point) {
|
||||
xcb_window_t window = XCB_WINDOW_NONE;
|
||||
xcb_window_t root = wm.screen->root;
|
||||
xcb_warp_pointer(wm.xcb_conn, window, root, 0, 0, 1, 1, point.x, point.y);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <X11/cursorfont.h>
|
||||
#include <xcb/xproto.h>
|
||||
|
||||
#include "base.h"
|
||||
|
||||
typedef enum cursor_t {
|
||||
cursor_normal = XC_left_ptr,
|
||||
cursor_resize = XC_bottom_right_corner,
|
||||
@@ -11,3 +13,5 @@ typedef enum cursor_t {
|
||||
|
||||
xcb_cursor_t xcursor_get_xcb_cursor(cursor_t cursor);
|
||||
void xcursor_clean(void);
|
||||
point_t xcursor_query_pointer_position(void);
|
||||
void xcursor_set_pointer_position(point_t point);
|
||||
|
||||
Reference in New Issue
Block a user