Add cursor handling
This commit is contained in:
		
							parent
							
								
									3f09b57ed0
								
							
						
					
					
						commit
						6794c5f943
					
				| @ -2,9 +2,9 @@ project('somebar', ['c', 'cpp'], | |||||||
|   default_options: ['cpp_std=c++17']) |   default_options: ['cpp_std=c++17']) | ||||||
| 
 | 
 | ||||||
| wayland_dep = dependency('wayland-client') | wayland_dep = dependency('wayland-client') | ||||||
|  | wayland_cursor_dep = dependency('wayland-cursor') | ||||||
| qt5 = import('qt5') | qt5 = import('qt5') | ||||||
| qt5_dep = dependency('qt5', modules: ['Core', 'Gui']) | qt5_dep = dependency('qt5', modules: ['Core', 'Gui']) | ||||||
| #moc = qt5.compile_moc(headers: [ 'src/.hpp', ]) |  | ||||||
| 
 | 
 | ||||||
| subdir('protocols') | subdir('protocols') | ||||||
| 
 | 
 | ||||||
| @ -13,5 +13,4 @@ executable('somebar', | |||||||
|   'src/shm_buffer.cpp', |   'src/shm_buffer.cpp', | ||||||
|   'src/bar.cpp', |   'src/bar.cpp', | ||||||
|   wayland_sources, |   wayland_sources, | ||||||
|   #moc, |   dependencies: [qt5_dep, wayland_dep, wayland_cursor_dep]) | ||||||
|   dependencies: [qt5_dep, wayland_dep]) |  | ||||||
|  | |||||||
							
								
								
									
										18
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/main.cpp
									
									
									
									
									
								
							| @ -14,6 +14,7 @@ | |||||||
| #include <QGuiApplication> | #include <QGuiApplication> | ||||||
| #include <QSocketNotifier> | #include <QSocketNotifier> | ||||||
| #include <wayland-client.h> | #include <wayland-client.h> | ||||||
|  | #include <wayland-cursor.h> | ||||||
| #include "wlr-layer-shell-unstable-v1-client-protocol.h" | #include "wlr-layer-shell-unstable-v1-client-protocol.h" | ||||||
| #include "xdg-shell-client-protocol.h" | #include "xdg-shell-client-protocol.h" | ||||||
| #include "common.hpp" | #include "common.hpp" | ||||||
| @ -46,15 +47,20 @@ static const struct xdg_wm_base_listener xdgWmBaseListener = { | |||||||
| 
 | 
 | ||||||
| struct PointerState { | struct PointerState { | ||||||
|     wl_pointer *pointer; |     wl_pointer *pointer; | ||||||
|  |     wl_surface *cursorSurface; | ||||||
|  |     wl_cursor_image *cursorImage; | ||||||
|     Bar *focusedBar; |     Bar *focusedBar; | ||||||
|     int x, y; |     int x, y; | ||||||
|     bool leftButtonClick; |     bool leftButtonClick; | ||||||
| }; | }; | ||||||
| static PointerState pointerState; | static PointerState pointerState; | ||||||
| static const struct wl_pointer_listener pointerListener = { | static const struct wl_pointer_listener pointerListener = { | ||||||
|     .enter = [](void*, wl_pointer*, uint32_t serial, wl_surface*, wl_fixed_t x, wl_fixed_t y) |     .enter = [](void*, wl_pointer *pointer, uint32_t serial, | ||||||
|  |                 wl_surface*, wl_fixed_t x, wl_fixed_t y) | ||||||
|     { |     { | ||||||
|         pointerState.focusedBar = &bar.value(); |         pointerState.focusedBar = &bar.value(); | ||||||
|  |         wl_pointer_set_cursor(pointer, serial, pointerState.cursorSurface, | ||||||
|  |             pointerState.cursorImage->hotspot_x, pointerState.cursorImage->hotspot_y); | ||||||
|     }, |     }, | ||||||
|     .leave = [](void*, wl_pointer*, uint32_t serial, wl_surface*) { |     .leave = [](void*, wl_pointer*, uint32_t serial, wl_surface*) { | ||||||
|         pointerState.focusedBar = nullptr; |         pointerState.focusedBar = nullptr; | ||||||
| @ -85,8 +91,14 @@ static wl_seat *seat; | |||||||
| static const struct wl_seat_listener seatListener = { | static const struct wl_seat_listener seatListener = { | ||||||
|     [](void*, wl_seat*, uint32_t cap) |     [](void*, wl_seat*, uint32_t cap) | ||||||
|     { |     { | ||||||
|         if (cap & WL_SEAT_CAPABILITY_POINTER) { |         if (!pointerState.pointer && WL_SEAT_CAPABILITY_POINTER) { | ||||||
|             printf("got pointer"); |             auto cursorTheme = wl_cursor_theme_load(NULL, 24, shm); | ||||||
|  |             auto cursorImage = wl_cursor_theme_get_cursor(cursorTheme, "left_ptr")->images[0]; | ||||||
|  |             pointerState.cursorImage = cursorImage; | ||||||
|  |             pointerState.cursorSurface = wl_compositor_create_surface(compositor); | ||||||
|  |             wl_surface_attach(pointerState.cursorSurface, | ||||||
|  |                 wl_cursor_image_get_buffer(cursorImage), 0, 0); | ||||||
|  |             wl_surface_commit(pointerState.cursorSurface); | ||||||
|             pointerState.pointer = wl_seat_get_pointer(seat); |             pointerState.pointer = wl_seat_get_pointer(seat); | ||||||
|             wl_pointer_add_listener(pointerState.pointer, &pointerListener, nullptr); |             wl_pointer_add_listener(pointerState.pointer, &pointerListener, nullptr); | ||||||
|         } |         } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user