添加记录和恢复光标在每个 monitor 中的位置功能
This commit is contained in:
@@ -11,3 +11,7 @@ typedef struct extent_in_bar_t {
|
|||||||
int16_t start;
|
int16_t start;
|
||||||
int16_t end;
|
int16_t end;
|
||||||
} extent_in_bar_t;
|
} extent_in_bar_t;
|
||||||
|
|
||||||
|
typedef struct point_t {
|
||||||
|
int16_t x, y;
|
||||||
|
} point_t;
|
||||||
|
|||||||
@@ -285,3 +285,21 @@ void monitor_arrange(monitor_t *monitor) {
|
|||||||
}
|
}
|
||||||
xcb_flush(wm.xcb_conn);
|
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_init_bar(monitor_t *monitor);
|
||||||
void monitor_draw_bar(monitor_t *monitor);
|
void monitor_draw_bar(monitor_t *monitor);
|
||||||
void monitor_arrange(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;
|
extent_in_bar_t layout_symbol_extent;
|
||||||
|
|
||||||
xcb_window_t bar_window;
|
xcb_window_t bar_window;
|
||||||
|
|
||||||
|
point_t cursor_position;
|
||||||
|
bool position_inited;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct tag_t {
|
struct tag_t {
|
||||||
|
|||||||
10
src/wm.c
10
src/wm.c
@@ -409,6 +409,16 @@ void wm_restack_clients(void) {
|
|||||||
xcb_flush(wm.xcb_conn);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
static void debug_show_monitor_list(void) {
|
static void debug_show_monitor_list(void) {
|
||||||
logger("\n========================== monitors ==========================\n");
|
logger("\n========================== monitors ==========================\n");
|
||||||
for (monitor_t *m = wm.monitor_list; m; m = m->next) {
|
for (monitor_t *m = wm.monitor_list; m; m = m->next) {
|
||||||
|
|||||||
2
src/wm.h
2
src/wm.h
@@ -5,6 +5,7 @@
|
|||||||
#include <xcb/xcb_xrm.h>
|
#include <xcb/xcb_xrm.h>
|
||||||
#include <xkbcommon/xkbcommon.h>
|
#include <xkbcommon/xkbcommon.h>
|
||||||
|
|
||||||
|
#include "base.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
typedef struct wm_t {
|
typedef struct wm_t {
|
||||||
@@ -52,3 +53,4 @@ extern wm_t wm;
|
|||||||
void wm_restart(void);
|
void wm_restart(void);
|
||||||
void wm_quit(void);
|
void wm_quit(void);
|
||||||
void wm_restack_clients(void);
|
void wm_restack_clients(void);
|
||||||
|
monitor_t *wm_get_monitor_by_point(point_t point);
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <xcb/xcb_cursor.h>
|
#include <xcb/xcb_cursor.h>
|
||||||
|
#include <xcb/xproto.h>
|
||||||
|
|
||||||
|
#include "base.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "wm.h"
|
#include "wm.h"
|
||||||
|
|
||||||
@@ -126,3 +128,19 @@ void xcursor_clean(void) {
|
|||||||
}
|
}
|
||||||
if (cursor_ctx) xcb_cursor_context_free(cursor_ctx);
|
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 <X11/cursorfont.h>
|
||||||
#include <xcb/xproto.h>
|
#include <xcb/xproto.h>
|
||||||
|
|
||||||
|
#include "base.h"
|
||||||
|
|
||||||
typedef enum cursor_t {
|
typedef enum cursor_t {
|
||||||
cursor_normal = XC_left_ptr,
|
cursor_normal = XC_left_ptr,
|
||||||
cursor_resize = XC_bottom_right_corner,
|
cursor_resize = XC_bottom_right_corner,
|
||||||
@@ -11,3 +13,5 @@ typedef enum cursor_t {
|
|||||||
|
|
||||||
xcb_cursor_t xcursor_get_xcb_cursor(cursor_t cursor);
|
xcb_cursor_t xcursor_get_xcb_cursor(cursor_t cursor);
|
||||||
void xcursor_clean(void);
|
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