22
33#include "wayland.h"
44#include "util/stringUtils.h"
5+ #include "xdg-output-unstable-v1-client-protocol.h"
56
67static void waylandOutputModeListener (void * data , FF_MAYBE_UNUSED struct wl_output * output , uint32_t flags , int32_t width , int32_t height , int32_t refreshRate )
78{
@@ -35,6 +36,39 @@ static void waylandOutputGeometryListener(void *data,
3536 display -> transform = (enum wl_output_transform ) transform ;
3637}
3738
39+ static void handleXdgLogicalSize (void * data , FF_MAYBE_UNUSED struct zxdg_output_v1 * _ , int32_t width , FF_MAYBE_UNUSED int32_t height )
40+ {
41+ WaylandDisplay * display = data ;
42+ // Seems the values are only useful when ractional scale is enabled
43+ if (width < display -> width )
44+ {
45+ display -> scale = (double ) display -> width / width ;
46+ }
47+ }
48+
49+ // Dirty hack for #477
50+ // The order of these callbacks MUST follow `struct wl_output_listener`
51+ static void * outputListener [] = {
52+ waylandOutputGeometryListener , // geometry
53+ waylandOutputModeListener , // mode
54+ stubListener , // done
55+ waylandOutputScaleListener , // scale
56+ ffWaylandOutputNameListener , // name
57+ ffWaylandOutputDescriptionListener , // description
58+ };
59+ static_assert (
60+ sizeof (outputListener ) >= sizeof (struct wl_output_listener ),
61+ "sizeof(outputListener) is too small. Please report it to fastfetch github issue"
62+ );
63+
64+ static struct zxdg_output_v1_listener zxdgOutputListener = {
65+ .logical_position = (void * ) stubListener ,
66+ .logical_size = handleXdgLogicalSize ,
67+ .done = (void * ) stubListener ,
68+ .name = (void * ) stubListener ,
69+ .description = (void * ) stubListener ,
70+ };
71+
3872void ffWaylandHandleGlobalOutput (WaylandData * wldata , struct wl_registry * registry , uint32_t name , uint32_t version )
3973{
4074 struct wl_proxy * output = wldata -> ffwl_proxy_marshal_constructor_versioned ((struct wl_proxy * ) registry , WL_REGISTRY_BIND , wldata -> ffwl_output_interface , version , name , wldata -> ffwl_output_interface -> name , version , NULL );
@@ -54,23 +88,21 @@ void ffWaylandHandleGlobalOutput(WaylandData* wldata, struct wl_registry* regist
5488 .edidName = ffStrbufCreate (),
5589 };
5690
57- // Dirty hack for #477
58- // The order of these callbacks MUST follow `struct wl_output_listener`
59- void * outputListener [] = {
60- waylandOutputGeometryListener , // geometry
61- waylandOutputModeListener , // mode
62- stubListener , // done
63- waylandOutputScaleListener , // scale
64- ffWaylandOutputNameListener , // name
65- ffWaylandOutputDescriptionListener , // description
66- };
67- static_assert (
68- sizeof (outputListener ) >= sizeof (struct wl_output_listener ),
69- "sizeof(outputListener) is too small. Please report it to fastfetch github issue"
70- );
71-
7291 wldata -> ffwl_proxy_add_listener (output , (void (* * )(void )) & outputListener , & display );
7392 wldata -> ffwl_display_roundtrip (wldata -> display );
93+
94+ if (wldata -> zxdgOutputManager )
95+ {
96+ struct wl_proxy * zxdgOutput = wldata -> ffwl_proxy_marshal_constructor_versioned (wldata -> zxdgOutputManager , ZXDG_OUTPUT_MANAGER_V1_GET_XDG_OUTPUT , & zxdg_output_v1_interface , version , NULL , output );
97+
98+ if (zxdgOutput )
99+ {
100+ wldata -> ffwl_proxy_add_listener (zxdgOutput , (void (* * )(void )) & zxdgOutputListener , & display );
101+ wldata -> ffwl_display_roundtrip (wldata -> display );
102+ wldata -> ffwl_proxy_destroy (zxdgOutput );
103+ }
104+ }
105+
74106 wldata -> ffwl_proxy_destroy (output );
75107
76108 if (display .width <= 0 || display .height <= 0 )
@@ -132,4 +164,13 @@ void ffWaylandHandleGlobalOutput(WaylandData* wldata, struct wl_registry* regist
132164 ffStrbufDestroy (& display .edidName );
133165}
134166
167+ void ffWaylandHandleXdgOutput (WaylandData * wldata , struct wl_registry * registry , uint32_t name , uint32_t version )
168+ {
169+ struct wl_proxy * manager = wldata -> ffwl_proxy_marshal_constructor_versioned ((struct wl_proxy * ) registry , WL_REGISTRY_BIND , & zxdg_output_manager_v1_interface , version , name , zxdg_output_manager_v1_interface .name , version , NULL );
170+ if (manager == NULL )
171+ return ;
172+
173+ wldata -> zxdgOutputManager = manager ;
174+ }
175+
135176#endif
0 commit comments