2020-05-04 21:31:23 +00:00
|
|
|
/*
|
|
|
|
* rofi
|
|
|
|
*
|
|
|
|
* MIT/X11 License
|
|
|
|
* Copyright © 2013-2020 Qball Cow <qball@gmpclient.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** The Rofi View log domain */
|
2021-09-06 11:01:37 +00:00
|
|
|
#define G_LOG_DOMAIN "View"
|
2020-05-04 21:31:23 +00:00
|
|
|
|
|
|
|
#include <config.h>
|
2021-09-06 11:01:37 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <locale.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdint.h>
|
2020-05-04 21:31:23 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2021-09-06 11:01:37 +00:00
|
|
|
#include <unistd.h>
|
2020-05-04 21:31:23 +00:00
|
|
|
|
|
|
|
#include <cairo.h>
|
|
|
|
|
|
|
|
#include "rofi.h"
|
|
|
|
#include "settings.h"
|
2021-09-06 11:01:37 +00:00
|
|
|
#include "timings.h"
|
2020-05-04 21:31:23 +00:00
|
|
|
|
|
|
|
#include "display.h"
|
|
|
|
#include "helper-theme.h"
|
2021-09-06 11:01:37 +00:00
|
|
|
#include "helper.h"
|
|
|
|
#include "mode.h"
|
2024-01-06 16:01:15 +00:00
|
|
|
#include "modes/modes.h"
|
2020-05-04 21:31:23 +00:00
|
|
|
|
|
|
|
#include "view-internal.h"
|
2021-09-06 11:01:37 +00:00
|
|
|
#include "view.h"
|
2020-05-04 21:31:23 +00:00
|
|
|
|
|
|
|
#include "theme.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param state The handle to the view
|
|
|
|
* @param qr Indicate if queue_redraw should be called on changes.
|
|
|
|
*
|
|
|
|
* Update the state of the view. This involves filter state.
|
|
|
|
*/
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_update(RofiViewState *state, gboolean qr);
|
2020-05-04 21:31:23 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_maybe_update(RofiViewState *state);
|
2020-06-05 01:24:26 +00:00
|
|
|
|
2020-05-04 21:31:23 +00:00
|
|
|
/**
|
2020-06-10 21:31:30 +00:00
|
|
|
* Structure holding some state
|
2020-05-04 21:31:23 +00:00
|
|
|
*/
|
2021-09-06 11:01:37 +00:00
|
|
|
static struct {
|
|
|
|
/** Main flags */
|
|
|
|
MenuFlags flags;
|
|
|
|
/** timeout for reloading */
|
|
|
|
guint idle_timeout;
|
|
|
|
/** debug counter for redraws */
|
|
|
|
unsigned long long count;
|
|
|
|
/** redraw idle time. */
|
|
|
|
guint repaint_source;
|
|
|
|
/** Window fullscreen */
|
|
|
|
gboolean fullscreen;
|
2022-02-05 12:13:17 +00:00
|
|
|
|
|
|
|
int monitor_width;
|
|
|
|
int monitor_height;
|
2020-06-10 21:31:30 +00:00
|
|
|
} WlState = {
|
2021-09-06 11:01:37 +00:00
|
|
|
.flags = MENU_NORMAL,
|
|
|
|
.idle_timeout = 0,
|
|
|
|
.count = 0L,
|
2020-05-04 21:31:23 +00:00
|
|
|
.repaint_source = 0,
|
2021-09-06 11:01:37 +00:00
|
|
|
.fullscreen = FALSE,
|
2022-02-05 12:13:17 +00:00
|
|
|
.monitor_width = 0,
|
|
|
|
.monitor_height = 0,
|
2020-05-04 21:31:23 +00:00
|
|
|
};
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_get_current_monitor(int *width, int *height) {
|
2022-02-05 12:13:17 +00:00
|
|
|
// TODO: handle changing monitor resolution
|
|
|
|
if (WlState.monitor_width == 0 && WlState.monitor_height == 0) {
|
2024-01-06 16:01:15 +00:00
|
|
|
display_get_surface_dimensions(&WlState.monitor_width,
|
|
|
|
&WlState.monitor_height);
|
2022-02-05 12:13:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (width) {
|
|
|
|
*width = WlState.monitor_width;
|
|
|
|
}
|
|
|
|
if (height) {
|
|
|
|
*height = WlState.monitor_height;
|
|
|
|
}
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
2020-05-27 23:30:41 +00:00
|
|
|
|
2020-05-04 21:31:23 +00:00
|
|
|
/**
|
|
|
|
* Stores a screenshot of Rofi at that point in time.
|
|
|
|
*/
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_capture_screenshot(void) {}
|
|
|
|
|
|
|
|
static gboolean wayland_rofi_view_repaint(G_GNUC_UNUSED void *data) {
|
|
|
|
RofiViewState *state = rofi_view_get_active();
|
|
|
|
if (state) {
|
|
|
|
// Repaint the view (if needed).
|
|
|
|
// After a resize the edit_pixmap surface might not contain anything
|
|
|
|
// anymore. If we already re-painted, this does nothing.
|
|
|
|
wayland_rofi_view_maybe_update(state);
|
|
|
|
WlState.repaint_source = 0;
|
|
|
|
}
|
|
|
|
return G_SOURCE_REMOVE;
|
2020-05-27 23:30:41 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 21:31:23 +00:00
|
|
|
static const int loc_transtable[9] = {
|
2021-09-06 11:01:37 +00:00
|
|
|
WL_CENTER, WL_NORTH | WL_WEST, WL_NORTH, WL_NORTH | WL_EAST,
|
|
|
|
WL_EAST, WL_SOUTH | WL_EAST, WL_SOUTH, WL_SOUTH | WL_WEST,
|
|
|
|
WL_WEST};
|
2020-05-04 21:31:23 +00:00
|
|
|
|
2024-01-06 16:01:15 +00:00
|
|
|
static void wayland_rofi_view_calculate_window_position(
|
|
|
|
G_GNUC_UNUSED RofiViewState *state) {}
|
2020-06-05 00:15:39 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static int rofi_get_location(RofiViewState *state) {
|
|
|
|
return rofi_theme_get_position(WIDGET(state->main_window), "location",
|
|
|
|
loc_transtable[config.location]);
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
2021-10-12 23:42:32 +00:00
|
|
|
static int rofi_get_offset_px(RofiViewState *state, RofiOrientation ori) {
|
|
|
|
char *property = ori == ROFI_ORIENTATION_HORIZONTAL ? "x-offset" : "y-offset";
|
|
|
|
|
2024-01-06 16:01:15 +00:00
|
|
|
RofiDistance offset =
|
|
|
|
rofi_theme_get_distance(WIDGET(state->main_window), property, 0);
|
2021-10-12 23:42:32 +00:00
|
|
|
return distance_get_pixel(offset, ori);
|
|
|
|
}
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_window_update_size(RofiViewState *state) {
|
|
|
|
if (state == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2021-10-12 23:42:32 +00:00
|
|
|
int offset_x = rofi_get_offset_px(state, ROFI_ORIENTATION_HORIZONTAL);
|
|
|
|
int offset_y = rofi_get_offset_px(state, ROFI_ORIENTATION_VERTICAL);
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
widget_resize(WIDGET(state->main_window), state->width, state->height);
|
2024-01-06 16:01:15 +00:00
|
|
|
display_set_surface_dimensions(state->width, state->height, offset_x,
|
|
|
|
offset_y, rofi_get_location(state));
|
2023-02-10 21:39:05 +00:00
|
|
|
rofi_view_pool_refresh();
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_set_size(RofiViewState *state, gint width,
|
|
|
|
gint height) {
|
|
|
|
if (width > -1) {
|
|
|
|
state->width = width;
|
|
|
|
}
|
|
|
|
if (height > -1) {
|
|
|
|
state->height = height;
|
|
|
|
}
|
|
|
|
wayland_rofi_view_window_update_size(state);
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_get_size(RofiViewState *state, gint *width,
|
|
|
|
gint *height) {
|
|
|
|
*width = state->width;
|
|
|
|
*height = state->height;
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_ping_mouse(RofiViewState *state) { (void)state; }
|
2021-09-06 11:00:57 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static gboolean wayland_rofi_view_reload_idle(G_GNUC_UNUSED gpointer data) {
|
|
|
|
RofiViewState *state = rofi_view_get_active();
|
2020-05-27 23:30:41 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
if (state) {
|
2022-07-16 10:37:31 +00:00
|
|
|
// For UI update on this.
|
|
|
|
if (state->tb_total_rows) {
|
2024-01-06 16:01:15 +00:00
|
|
|
char *r = g_strdup_printf("%u", mode_get_num_entries(state->sw));
|
2022-07-16 10:37:31 +00:00
|
|
|
textbox_text(state->tb_total_rows, r);
|
|
|
|
g_free(r);
|
|
|
|
}
|
2021-09-06 11:01:37 +00:00
|
|
|
state->reload = TRUE;
|
|
|
|
state->refilter = TRUE;
|
2020-05-27 23:30:41 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
wayland_rofi_view_maybe_update(state);
|
|
|
|
}
|
|
|
|
WlState.idle_timeout = 0;
|
|
|
|
return G_SOURCE_REMOVE;
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_reload(void) {
|
|
|
|
// @TODO add check if current view is equal to the callee
|
|
|
|
if (WlState.idle_timeout == 0) {
|
|
|
|
WlState.idle_timeout =
|
|
|
|
g_timeout_add(1000 / 15, wayland_rofi_view_reload_idle, NULL);
|
|
|
|
}
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_queue_redraw(void) {
|
|
|
|
RofiViewState *state = rofi_view_get_active();
|
|
|
|
if (state && WlState.repaint_source == 0) {
|
|
|
|
WlState.count++;
|
|
|
|
g_debug("redraw %llu", WlState.count);
|
2020-05-27 23:30:41 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
widget_queue_redraw(WIDGET(state->main_window));
|
2020-05-27 23:30:41 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
WlState.repaint_source = g_idle_add_full(
|
|
|
|
G_PRIORITY_HIGH_IDLE, wayland_rofi_view_repaint, NULL, NULL);
|
|
|
|
}
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Thread state for workers started for the view.
|
|
|
|
*/
|
2021-09-06 11:01:37 +00:00
|
|
|
typedef struct _thread_state_view {
|
|
|
|
/** Generic thread state. */
|
|
|
|
thread_state st;
|
|
|
|
|
|
|
|
/** Condition. */
|
|
|
|
GCond *cond;
|
|
|
|
/** Lock for condition. */
|
|
|
|
GMutex *mutex;
|
|
|
|
/** Count that is protected by lock. */
|
|
|
|
unsigned int *acount;
|
|
|
|
|
|
|
|
/** Current state. */
|
|
|
|
RofiViewState *state;
|
|
|
|
/** Start row for this worker. */
|
|
|
|
unsigned int start;
|
|
|
|
/** Stop row for this worker. */
|
|
|
|
unsigned int stop;
|
|
|
|
/** Rows processed. */
|
|
|
|
unsigned int count;
|
|
|
|
|
|
|
|
/** Pattern input to filter. */
|
|
|
|
const char *pattern;
|
|
|
|
/** Length of pattern. */
|
|
|
|
glong plen;
|
2020-05-04 21:31:23 +00:00
|
|
|
} thread_state_view;
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland___create_window(MenuFlags menu_flags) {
|
2023-09-14 14:40:37 +00:00
|
|
|
// In password mode, disable the entry history.
|
|
|
|
if ((menu_flags & MENU_PASSWORD) == MENU_PASSWORD) {
|
|
|
|
CacheState.entry_history_enable = FALSE;
|
|
|
|
}
|
|
|
|
input_history_initialize();
|
2021-09-06 11:01:37 +00:00
|
|
|
|
|
|
|
TICK_N("create cairo surface");
|
|
|
|
// TODO should we update the drawable each time?
|
|
|
|
PangoContext *p = pango_context_new();
|
|
|
|
pango_context_set_font_map(p, pango_cairo_font_map_get_default());
|
|
|
|
TICK_N("pango cairo font setup");
|
|
|
|
|
|
|
|
WlState.flags = menu_flags;
|
2023-01-09 05:46:28 +00:00
|
|
|
// Setup dpi
|
|
|
|
PangoFontMap *font_map = pango_cairo_font_map_get_default();
|
|
|
|
if (config.dpi > 1) {
|
|
|
|
pango_cairo_font_map_set_resolution((PangoCairoFontMap *)font_map,
|
|
|
|
(double)config.dpi);
|
|
|
|
} else if (config.dpi == 0 || config.dpi == 1) {
|
|
|
|
// Should not be reached
|
|
|
|
g_warning("DPI auto-detect failed, the output is not known yet or does not "
|
|
|
|
"provide a physical size");
|
|
|
|
config.dpi =
|
|
|
|
pango_cairo_font_map_get_resolution((PangoCairoFontMap *)font_map);
|
|
|
|
} else {
|
|
|
|
// default pango is 96.
|
|
|
|
config.dpi =
|
|
|
|
pango_cairo_font_map_get_resolution((PangoCairoFontMap *)font_map);
|
|
|
|
}
|
2021-09-06 11:01:37 +00:00
|
|
|
// Setup font.
|
|
|
|
// Dummy widget.
|
|
|
|
box *win = box_create(NULL, "window", ROFI_ORIENTATION_HORIZONTAL);
|
|
|
|
const char *font =
|
|
|
|
rofi_theme_get_string(WIDGET(win), "font", config.menu_font);
|
|
|
|
if (font) {
|
|
|
|
PangoFontDescription *pfd = pango_font_description_from_string(font);
|
|
|
|
if (helper_validate_font(pfd, font)) {
|
|
|
|
pango_context_set_font_description(p, pfd);
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
2021-09-06 11:01:37 +00:00
|
|
|
pango_font_description_free(pfd);
|
|
|
|
}
|
|
|
|
PangoLanguage *l = pango_language_get_default();
|
|
|
|
pango_context_set_language(p, l);
|
|
|
|
TICK_N("configure font");
|
2020-05-04 21:31:23 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
// Tell textbox to use this context.
|
|
|
|
textbox_set_pango_context(font, p);
|
|
|
|
// cleanup
|
|
|
|
g_object_unref(p);
|
2020-05-04 21:31:23 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
WlState.fullscreen = rofi_theme_get_boolean(WIDGET(win), "fullscreen", FALSE);
|
2020-09-02 18:51:10 +00:00
|
|
|
|
2023-02-10 23:12:21 +00:00
|
|
|
if (WlState.fullscreen) {
|
|
|
|
display_set_fullscreen_mode();
|
|
|
|
}
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
widget_free(WIDGET(win));
|
2020-09-02 18:51:10 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
TICK_N("done");
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param state Internal state of the menu.
|
|
|
|
*
|
|
|
|
* Calculate the width of the window and the width of an element.
|
|
|
|
*/
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_calculate_window_width(RofiViewState *state) {
|
|
|
|
int screen_width = 1920;
|
|
|
|
display_get_surface_dimensions(&screen_width, NULL);
|
|
|
|
|
|
|
|
if (WlState.fullscreen == TRUE) {
|
|
|
|
state->width = screen_width;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate as float to stop silly, big rounding down errors.
|
|
|
|
state->width = (screen_width / 100.0f) * DEFAULT_MENU_WIDTH;
|
|
|
|
// Use theme configured width, if set.
|
|
|
|
RofiDistance width = rofi_theme_get_distance(WIDGET(state->main_window),
|
|
|
|
"width", state->width);
|
|
|
|
state->width = distance_get_pixel(width, ROFI_ORIENTATION_HORIZONTAL);
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_update(RofiViewState *state, gboolean qr) {
|
|
|
|
if (!widget_need_redraw(WIDGET(state->main_window))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
g_debug("Redraw view");
|
|
|
|
TICK();
|
|
|
|
if (state->pool == NULL) {
|
|
|
|
state->pool = display_buffer_pool_new(state->width, state->height);
|
|
|
|
}
|
|
|
|
cairo_surface_t *surface = display_buffer_pool_get_next_buffer(state->pool);
|
|
|
|
if (surface == NULL) {
|
|
|
|
// no available buffer, bail out
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cairo_t *d = cairo_create(surface);
|
|
|
|
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");
|
|
|
|
|
|
|
|
// Always paint as overlay over the background.
|
|
|
|
cairo_set_operator(d, CAIRO_OPERATOR_OVER);
|
|
|
|
widget_draw(WIDGET(state->main_window), d);
|
|
|
|
|
|
|
|
TICK_N("widgets");
|
|
|
|
cairo_destroy(d);
|
|
|
|
display_surface_commit(surface);
|
|
|
|
|
|
|
|
if (qr) {
|
|
|
|
wayland_rofi_view_queue_redraw();
|
|
|
|
}
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param state The Menu Handle
|
|
|
|
*
|
|
|
|
* Check if a finalize function is set, and if sets executes it.
|
|
|
|
*/
|
2021-09-06 11:01:37 +00:00
|
|
|
void process_result(RofiViewState *state);
|
|
|
|
|
|
|
|
static void wayland_rofi_view_maybe_update(RofiViewState *state) {
|
|
|
|
if (rofi_view_get_completed(state)) {
|
|
|
|
// This menu is done.
|
|
|
|
rofi_view_finalize(state);
|
|
|
|
// If there a state. (for example error) reload it.
|
|
|
|
state = rofi_view_get_active();
|
|
|
|
|
|
|
|
// cleanup, if no more state to display.
|
|
|
|
if (state == NULL) {
|
|
|
|
// Quit main-loop.
|
|
|
|
rofi_quit_main_loop();
|
|
|
|
return;
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
2021-09-06 11:01:37 +00:00
|
|
|
}
|
2020-05-04 21:31:23 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
// Update if requested.
|
|
|
|
if (state->refilter) {
|
|
|
|
rofi_view_refilter(state);
|
|
|
|
}
|
|
|
|
wayland_rofi_view_update(state, TRUE);
|
2022-07-16 10:37:31 +00:00
|
|
|
return;
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_frame_callback(void) {
|
|
|
|
if (WlState.repaint_source == 0) {
|
|
|
|
WlState.repaint_source = g_idle_add_full(
|
|
|
|
G_PRIORITY_HIGH_IDLE, wayland_rofi_view_repaint, NULL, NULL);
|
|
|
|
}
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static int wayland_rofi_view_calculate_window_height(RofiViewState *state) {
|
|
|
|
if (WlState.fullscreen == TRUE) {
|
|
|
|
int height = 1080;
|
|
|
|
display_get_surface_dimensions(NULL, &height);
|
|
|
|
return height;
|
|
|
|
}
|
2020-05-04 21:31:23 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
RofiDistance h =
|
|
|
|
rofi_theme_get_distance(WIDGET(state->main_window), "height", 0);
|
|
|
|
unsigned int height = distance_get_pixel(h, ROFI_ORIENTATION_VERTICAL);
|
|
|
|
// If height is set, return it.
|
|
|
|
if (height > 0) {
|
2020-05-04 21:31:23 +00:00
|
|
|
return height;
|
2021-09-06 11:01:37 +00:00
|
|
|
}
|
|
|
|
// Autosize based on widgets.
|
|
|
|
widget *main_window = WIDGET(state->main_window);
|
2020-05-04 21:31:23 +00:00
|
|
|
|
2023-02-10 21:39:05 +00:00
|
|
|
return widget_get_desired_height(main_window, state->width);
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
2024-02-26 04:01:41 +00:00
|
|
|
static void wayland_rofi_view_hide(void) { display_early_cleanup(); }
|
2020-05-04 21:31:23 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
static void wayland_rofi_view_cleanup() {
|
|
|
|
g_debug("Cleanup.");
|
|
|
|
if (WlState.idle_timeout > 0) {
|
|
|
|
g_source_remove(WlState.idle_timeout);
|
|
|
|
WlState.idle_timeout = 0;
|
|
|
|
}
|
2022-07-16 10:37:31 +00:00
|
|
|
if (CacheState.user_timeout > 0) {
|
|
|
|
g_source_remove(CacheState.user_timeout);
|
|
|
|
CacheState.user_timeout = 0;
|
|
|
|
}
|
|
|
|
if (CacheState.refilter_timeout > 0) {
|
|
|
|
g_source_remove(CacheState.refilter_timeout);
|
|
|
|
CacheState.refilter_timeout = 0;
|
|
|
|
}
|
2021-09-06 11:01:37 +00:00
|
|
|
if (WlState.repaint_source > 0) {
|
|
|
|
g_source_remove(WlState.repaint_source);
|
|
|
|
WlState.repaint_source = 0;
|
|
|
|
}
|
2023-09-14 14:40:37 +00:00
|
|
|
|
|
|
|
input_history_save();
|
2020-05-04 21:31:23 +00:00
|
|
|
}
|
|
|
|
|
2024-01-06 16:01:15 +00:00
|
|
|
static void
|
|
|
|
wayland_rofi_view_set_window_title(G_GNUC_UNUSED const char *title) {}
|
2021-09-06 11:01:37 +00:00
|
|
|
|
|
|
|
static void wayland_rofi_view_pool_refresh(void) {
|
|
|
|
RofiViewState *state = rofi_view_get_active();
|
|
|
|
if (state == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
display_buffer_pool_free(state->pool);
|
|
|
|
state->pool = NULL;
|
|
|
|
wayland_rofi_view_update(state, TRUE);
|
2020-06-10 14:55:49 +00:00
|
|
|
}
|
|
|
|
|
2020-06-02 19:29:28 +00:00
|
|
|
static view_proxy view_ = {
|
2021-09-06 11:01:37 +00:00
|
|
|
.update = wayland_rofi_view_update,
|
|
|
|
.maybe_update = wayland_rofi_view_maybe_update,
|
2020-06-02 19:29:28 +00:00
|
|
|
.temp_configure_notify = NULL,
|
2021-09-06 11:01:37 +00:00
|
|
|
.temp_click_to_exit = NULL,
|
|
|
|
.frame_callback = wayland_rofi_view_frame_callback,
|
|
|
|
.queue_redraw = wayland_rofi_view_queue_redraw,
|
2020-06-02 19:29:28 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
.set_window_title = wayland_rofi_view_set_window_title,
|
2020-06-05 00:15:39 +00:00
|
|
|
.calculate_window_position = wayland_rofi_view_calculate_window_position,
|
2021-09-06 11:01:37 +00:00
|
|
|
.calculate_window_height = wayland_rofi_view_calculate_window_height,
|
|
|
|
.calculate_window_width = wayland_rofi_view_calculate_window_width,
|
|
|
|
.window_update_size = wayland_rofi_view_window_update_size,
|
2024-01-07 17:25:33 +00:00
|
|
|
.set_cursor = wayland_display_set_cursor_type,
|
2021-09-06 11:01:37 +00:00
|
|
|
.ping_mouse = wayland_rofi_view_ping_mouse,
|
2020-06-05 00:15:39 +00:00
|
|
|
|
2020-06-02 19:29:28 +00:00
|
|
|
.cleanup = wayland_rofi_view_cleanup,
|
2021-09-06 11:01:37 +00:00
|
|
|
.hide = wayland_rofi_view_hide,
|
|
|
|
.reload = wayland_rofi_view_reload,
|
2020-06-10 21:31:30 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
.__create_window = wayland___create_window,
|
|
|
|
.get_window = NULL,
|
2020-06-02 19:29:28 +00:00
|
|
|
.get_current_monitor = wayland_rofi_view_get_current_monitor,
|
2021-09-06 11:01:37 +00:00
|
|
|
.capture_screenshot = wayland_rofi_view_capture_screenshot,
|
2020-06-02 19:29:28 +00:00
|
|
|
|
|
|
|
.set_size = wayland_rofi_view_set_size,
|
|
|
|
.get_size = wayland_rofi_view_get_size,
|
2020-06-10 14:55:49 +00:00
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
.pool_refresh = wayland_rofi_view_pool_refresh,
|
2020-06-02 19:29:28 +00:00
|
|
|
};
|
|
|
|
|
2021-09-06 11:01:37 +00:00
|
|
|
const view_proxy *wayland_view_proxy = &view_;
|