2
0
Fork 0
mirror of https://github.com/lbonn/rofi synced 2025-03-01 05:37:08 +00:00

wayland: High DPI support

This commit is contained in:
lbonn 2020-06-10 16:55:49 +02:00
parent 17b4265a5f
commit 04d2a7a73d
8 changed files with 46 additions and 34 deletions

View file

@ -43,6 +43,7 @@ typedef struct _display_proxy {
void (*dump_monitor_layout) ( void );
void (*startup_notification) ( RofiHelperExecuteContext *context, GSpawnChildSetupFunc *child_setup, gpointer *user_data );
int (*monitor_active) ( struct _workarea *mon );
guint (*scale) ( void );
const struct _view_proxy* (*view) ( void );
} display_proxy;

View file

@ -116,5 +116,6 @@ void display_dump_monitor_layout ( void );
*/
void display_startup_notification ( RofiHelperExecuteContext *context, GSpawnChildSetupFunc *child_setup, gpointer *user_data );
guint display_scale ( void );
#endif

View file

@ -177,6 +177,8 @@ typedef struct _view_proxy {
void (*set_size) ( RofiViewState * state, gint width, gint height );
void (*get_size) ( RofiViewState * state, gint *width, gint *height );
void (*pool_refresh) ( );
} view_proxy;
/**

View file

@ -316,7 +316,7 @@ void rofi_view_set_size ( RofiViewState * state, gint width, gint height );
void rofi_view_get_size ( RofiViewState * state, gint *width, gint *height );
void rofi_view_set_window_tilte ( const char * title );
void rofi_view_pool_refresh ( void );
struct _view_proxy;

View file

@ -58,3 +58,8 @@ display_startup_notification ( RofiHelperExecuteContext *context, GSpawnChildSet
proxy->startup_notification ( context, child_setup, user_data );
}
guint
display_scale ( void )
{
return proxy->scale ( );
}

View file

@ -1416,3 +1416,7 @@ void rofi_view_set_size ( RofiViewState * state, gint width, gint height ) {
void rofi_view_get_size ( RofiViewState * state, gint *width, gint *height ) {
proxy->get_size ( state, width, height );
}
void rofi_view_pool_refresh ( void ) {
proxy->pool_refresh ( );
}

View file

@ -148,7 +148,6 @@ display_buffer_pool_new(gint width, gint height)
gchar filename[PATH_MAX];
g_snprintf(filename, PATH_MAX, "%s/rofi-wayland-surface", g_get_user_runtime_dir());
//fd = g_open(filename, O_CREAT | O_RDWR | O_CLOEXEC, 0);
fd = g_open(filename, O_CREAT | O_RDWR, 0);
g_unlink(filename);
if ( fd < 0 )
@ -214,14 +213,15 @@ wayland_surface_protocol_enter(void *data, struct wl_surface *wl_surface, struct
output = g_hash_table_lookup(wayland->outputs, wl_output);
if ( output == NULL )
return;
if ( ( output->scale < 1 ) || ( output->scale > 3 ) )
return;
++wayland->scales[output->scale - 1];
if ( wayland->scale < output->scale )
wl_surface_set_buffer_scale( wl_surface, output->scale );
if ( wayland->scale != output->scale )
{
wayland->scale = output->scale;
// create new buffers with the correct scaled size
rofi_view_pool_refresh ( );
rofi_view_set_size(rofi_view_get_active(), -1, -1);
}
}
@ -229,25 +229,6 @@ wayland_surface_protocol_enter(void *data, struct wl_surface *wl_surface, struct
static void
wayland_surface_protocol_leave(void *data, struct wl_surface *wl_surface, struct wl_output *wl_output)
{
wayland_output *output;
output = g_hash_table_lookup(wayland->outputs, wl_output);
if ( output == NULL )
return;
if ( ( output->scale < 1 ) || ( output->scale > 3 ) )
return;
if ( ( --wayland->scales[output->scale - 1] < 1 ) && ( wayland->scale == output->scale ) )
{
int32_t i;
for ( i = 0 ; i < 3 ; ++i )
{
if ( wayland->scales[i] > 0 )
wayland->scale = i + 1;
}
rofi_view_set_size(rofi_view_get_active(), -1, -1);
}
}
static const struct wl_surface_listener wayland_surface_interface = {
@ -295,8 +276,8 @@ display_surface_commit(cairo_surface_t *surface)
wl_surface_damage(wayland->surface, 0, 0, pool->width, pool->height);
wl_surface_attach(wayland->surface, buffer->buffer, 0, 0);
if ( wl_surface_get_version(wayland->surface) >= WL_SURFACE_SET_BUFFER_SCALE_SINCE_VERSION )
wl_surface_set_buffer_scale(wayland->surface, wayland->scale);
// FIXME: hidpi
wl_surface_set_buffer_scale(wayland->surface, wayland->scale);
buffer->released = FALSE;
wl_surface_commit( wayland->surface );
@ -354,7 +335,6 @@ wayland_keyboard_enter(void *data, struct wl_keyboard *keyboard, uint32_t serial
uint32_t *key, *kend;
for ( key = keys->data, kend = key + keys->size / sizeof(*key) ; key < kend ; ++key ) {
// TODO: check
nk_bindings_seat_handle_key( wayland->bindings_seat, NULL, *key + 8, NK_BINDINGS_KEY_STATE_PRESSED );
}
}
@ -1034,13 +1014,8 @@ wayland_display_setup(GMainLoop *main_loop, NkBindings *bindings)
wayland->bindings_seat = nk_bindings_seat_new ( bindings, XKB_CONTEXT_NO_FLAGS );
wayland->wlr_surface = zwlr_layer_shell_v1_get_layer_surface(wayland->layer_shell, wayland->surface, NULL, ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY, "rofi");
return TRUE;
}
static gboolean
wayland_display_late_setup ( void )
{
// note: ANCHOR_LEFT is needed to get the full window width
// ANCHOR_LEFT is needed to get the full screen width
zwlr_layer_surface_v1_set_anchor( wayland->wlr_surface, ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT );
zwlr_layer_surface_v1_set_keyboard_interactivity( wayland->wlr_surface, 1 );
zwlr_layer_surface_v1_add_listener( wayland->wlr_surface, &wayland_layer_shell_surface_listener, NULL );
@ -1055,6 +1030,12 @@ wayland_display_late_setup ( void )
return TRUE;
}
static gboolean
wayland_display_late_setup ( void )
{
return TRUE;
}
gboolean
display_get_surface_dimensions ( int *width, int *height )
{
@ -1154,6 +1135,11 @@ static const struct _view_proxy* wayland_display_view_proxy ( void )
return wayland_view_proxy;
}
static guint wayland_display_scale ( void )
{
return wayland->scale;
}
static display_proxy display_ = {
.setup = wayland_display_setup,
.late_setup = wayland_display_late_setup,
@ -1162,6 +1148,7 @@ static display_proxy display_ = {
.dump_monitor_layout = wayland_display_dump_monitor_layout,
.startup_notification = wayland_display_startup_notification,
.monitor_active = wayland_display_monitor_active,
.scale = wayland_display_scale,
.view = wayland_display_view_proxy,
};

View file

@ -301,6 +301,8 @@ static void wayland_rofi_view_update ( RofiViewState *state, gboolean qr )
cairo_set_operator ( d, CAIRO_OPERATOR_SOURCE );
// Paint the background transparent.
cairo_set_source_rgba ( d, 0, 0, 0, 0.0 );
guint scale = display_scale ( );
cairo_surface_set_device_scale ( surface, scale, scale );
cairo_paint ( d );
TICK_N ( "Background" );
@ -396,6 +398,14 @@ static void wayland_rofi_view_set_window_title ( const char * title )
{
}
static void wayland_rofi_view_pool_refresh ( void )
{
RofiViewState *state = rofi_view_get_active ();
display_buffer_pool_free ( state->pool );
state->pool = NULL;
wayland_rofi_view_update ( state, TRUE);
}
static view_proxy view_ = {
.update = wayland_rofi_view_update,
.maybe_update = wayland_rofi_view_maybe_update,
@ -421,6 +431,8 @@ static view_proxy view_ = {
.set_size = wayland_rofi_view_set_size,
.get_size = wayland_rofi_view_get_size,
.pool_refresh = wayland_rofi_view_pool_refresh,
};
const view_proxy *wayland_view_proxy = &view_;