Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IconFetcher] Fix ABI compatibility with upstream rofi #97

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions include/mode-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,14 @@ typedef char *(*_mode_get_display_value)(const Mode *sw,
* @param sw The #Mode pointer
* @param selected_line The selected line
* @param height The height of the icon
* @param scale The scale of the icon
*
* Obtains the icon if available
*
* @return Get the icon
*/
typedef cairo_surface_t *(*_mode_get_icon)(const Mode *sw,
unsigned int selected_line,
unsigned int height,
guint scale);
unsigned int height);

/**
* @param sw The #Mode pointer
Expand Down
3 changes: 1 addition & 2 deletions include/mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,13 @@ char *mode_get_display_value(const Mode *mode, unsigned int selected_line,
* @param mode The mode to query
* @param selected_line The entry to query
* @param height The desired height of the icon.
* @param scale The desired scale of the icon.
*
* Returns the icon for the selected_line
*
* @returns allocated new cairo_surface_t if applicable
*/
cairo_surface_t *mode_get_icon(Mode *mode, unsigned int selected_line,
unsigned int height, guint scale);
unsigned int height);

/**
* @param mode The mode to query
Expand Down
11 changes: 4 additions & 7 deletions include/rofi-icon-fetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,23 @@ void rofi_icon_fetcher_destroy(void);
/**
* @param name The name of the icon to fetch.
* @param size The size of the icon to fetch.
* @param scale The scale of the icon to fetch.
*
* Query the icon-theme for icon with name, size, and scale.
* Query the icon-theme for icon with name and size.
* The returned icon will be the best match for the requested size, it should
* still be resized to the actual size.
*
* name can also be a full path, if prefixed with file://.
*
* @returns the uid identifying the request.
*/
uint32_t rofi_icon_fetcher_query(const char *name, const int size,
const guint scale);
uint32_t rofi_icon_fetcher_query(const char *name, const int size);

/**
* @param name The name of the icon to fetch.
* @param wsize The width of the icon to fetch.
* @param hsize The height of the icon to fetch.
* @param scale The scale of the icon to fetch.
*
* Query the icon-theme for icon with name, size, and scale.
* Query the icon-theme for icon with name and size.
* The returned icon will be the best match for the requested size, it should
* still be resized to the actual size. For icons it will take the min of wsize
* and hsize.
Expand All @@ -55,7 +52,7 @@ uint32_t rofi_icon_fetcher_query(const char *name, const int size,
* @returns the uid identifying the request.
*/
uint32_t rofi_icon_fetcher_query_advanced(const char *name, const int wsize,
const int hsize, const guint scale);
const int hsize);

/**
* @param uid The unique id representing the matching request.
Expand Down
1 change: 0 additions & 1 deletion include/rofi-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ typedef struct {
RofiScaleType scaling;
int wsize;
int hsize;
guint scale;

RofiDirection dir;
double angle;
Expand Down
6 changes: 3 additions & 3 deletions source/mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ char *mode_get_display_value(const Mode *mode, unsigned int selected_line,
}

cairo_surface_t *mode_get_icon(Mode *mode, unsigned int selected_line,
unsigned int height, guint scale) {
unsigned int height) {
g_assert(mode != NULL);

if (mode->_get_icon != NULL) {
cairo_surface_t *icon = mode->_get_icon(mode, selected_line, height, scale);
cairo_surface_t *icon = mode->_get_icon(mode, selected_line, height);
if (icon) {
return icon;
}
Expand All @@ -110,7 +110,7 @@ cairo_surface_t *mode_get_icon(Mode *mode, unsigned int selected_line,
rofi_theme_find_property(wid, P_STRING, "fallback-icon", TRUE);
if (p != NULL && (p->type == P_STRING && p->value.s)) {
mode->fallback_icon_fetch_uid =
rofi_icon_fetcher_query(p->value.s, height, scale);
rofi_icon_fetcher_query(p->value.s, height);
return NULL;
}
}
Expand Down
10 changes: 5 additions & 5 deletions source/modes/combi.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ static char *combi_get_completion(const Mode *sw, unsigned int index) {
}

static cairo_surface_t *combi_get_icon(const Mode *sw, unsigned int index,
unsigned int height, guint scale) {
unsigned int height) {
CombiModePrivateData *pd = mode_get_private_data(sw);
for (unsigned i = 0; i < pd->num_switchers; i++) {
if (index >= pd->starts[i] && index < (pd->starts[i] + pd->lengths[i])) {
cairo_surface_t *icon = mode_get_icon(
pd->switchers[i].mode, index - pd->starts[i], height, scale);
cairo_surface_t *icon =
mode_get_icon(pd->switchers[i].mode, index - pd->starts[i], height);
return icon;
}
}
Expand Down Expand Up @@ -342,5 +342,5 @@ Mode combi_mode = {.name = "combi",
._get_icon = combi_get_icon,
._preprocess_input = combi_preprocess_input,
.private_data = NULL,
.free = NULL,
.type = MODE_TYPE_SWITCHER };
.free = NULL,
.type = MODE_TYPE_SWITCHER};
12 changes: 6 additions & 6 deletions source/modes/dmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define G_LOG_DOMAIN "Modes.DMenu"
#include "config.h"

#include "display.h"
#include "helper.h"
#include "modes/dmenu.h"
#include "rofi-icon-fetcher.h"
Expand Down Expand Up @@ -57,9 +58,8 @@
static int dmenu_mode_init(Mode *sw);
static int dmenu_token_match(const Mode *sw, rofi_int_matcher **tokens,
unsigned int index);
static cairo_surface_t *dmenu_get_icon(const Mode *sw,
unsigned int selected_line,
unsigned int height, guint scale);
static cairo_surface_t *
dmenu_get_icon(const Mode *sw, unsigned int selected_line, unsigned int height);
static char *dmenu_get_message(const Mode *sw);

static inline unsigned int bitget(uint32_t const *const array,
Expand Down Expand Up @@ -698,9 +698,9 @@ static char *dmenu_get_message(const Mode *sw) {
}
static cairo_surface_t *dmenu_get_icon(const Mode *sw,
unsigned int selected_line,
unsigned int height,
guint scale) {
unsigned int height) {
DmenuModePrivateData *pd = (DmenuModePrivateData *)mode_get_private_data(sw);
const guint scale = display_scale();

g_return_val_if_fail(pd->cmd_list != NULL, NULL);
DmenuScriptEntry *dr = &(pd->cmd_list[selected_line]);
Expand All @@ -712,7 +712,7 @@ static cairo_surface_t *dmenu_get_icon(const Mode *sw,
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
uint32_t uid = dr->icon_fetch_uid =
rofi_icon_fetcher_query(dr->icon_name, height, scale);
rofi_icon_fetcher_query(dr->icon_name, height);
dr->icon_fetch_size = height;
dr->icon_fetch_scale = scale;

Expand Down
9 changes: 5 additions & 4 deletions source/modes/drun.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <sys/types.h>
#include <unistd.h>

#include "display.h"
#include "helper.h"
#include "history.h"
#include "mode-private.h"
Expand Down Expand Up @@ -1349,11 +1350,11 @@ static char *_get_display_value(const Mode *sw, unsigned int selected_line,
}

static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
unsigned int height, guint scale) {
unsigned int height) {
DRunModePrivateData *pd = (DRunModePrivateData *)mode_get_private_data(sw);
const guint scale = display_scale();
if (pd->file_complete) {
return pd->completer->_get_icon(pd->completer, selected_line, height,
scale);
return pd->completer->_get_icon(pd->completer, selected_line, height);
}
g_return_val_if_fail(pd->entry_list != NULL, NULL);
DRunModeEntry *dr = &(pd->entry_list[selected_line]);
Expand All @@ -1363,7 +1364,7 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid);
return icon;
}
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->icon_name, height, scale);
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->icon_name, height);
dr->icon_fetch_size = height;
dr->icon_fetch_scale = scale;
cairo_surface_t *icon = rofi_icon_fetcher_get(dr->icon_fetch_uid);
Expand Down
8 changes: 5 additions & 3 deletions source/modes/filebrowser.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <sys/stat.h>
#include <sys/types.h>

#include "display.h"
#include "helper.h"
#include "history.h"
#include "mode-private.h"
Expand Down Expand Up @@ -608,19 +609,20 @@ static int file_browser_token_match(const Mode *sw, rofi_int_matcher **tokens,
}

static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
unsigned int height, guint scale) {
unsigned int height) {
FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw);
const guint scale = display_scale();
g_return_val_if_fail(pd->array != NULL, NULL);
FBFile *dr = &(pd->array[selected_line]);
if (dr->icon_fetch_uid > 0 && dr->icon_fetch_size == height &&
dr->icon_fetch_scale == scale) {
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
if (rofi_icon_fetcher_file_is_image(dr->path)) {
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->path, height, scale);
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->path, height);
} else {
dr->icon_fetch_uid = rofi_icon_fetcher_query(icon_name[dr->type], height, scale);
dr->icon_fetch_uid = rofi_icon_fetcher_query(icon_name[dr->type], height);
}
dr->icon_fetch_size = height;
dr->icon_fetch_scale = scale;
Expand Down
15 changes: 11 additions & 4 deletions source/modes/recursivebrowser.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <sys/stat.h>
#include <sys/types.h>

#include "display.h"
#include "helper.h"
#include "history.h"
#include "mode-private.h"
Expand Down Expand Up @@ -73,6 +74,7 @@ typedef struct {
enum FBFileType type;
uint32_t icon_fetch_uid;
uint32_t icon_fetch_size;
guint icon_fetch_scale;
gboolean link;
time_t time;
} FBFile;
Expand Down Expand Up @@ -212,6 +214,7 @@ static void scan_dir(FileBrowserModePrivateData *pd, GFile *path) {
f->type = (rd->d_type == DT_DIR) ? DIRECTORY : RFILE;
f->icon_fetch_uid = 0;
f->icon_fetch_size = 0;
f->icon_fetch_scale = 0;
f->link = FALSE;

g_async_queue_push(pd->async_queue, f);
Expand All @@ -238,6 +241,7 @@ static void scan_dir(FileBrowserModePrivateData *pd, GFile *path) {
}
f->icon_fetch_uid = 0;
f->icon_fetch_size = 0;
f->icon_fetch_scale = 0;
f->link = TRUE;
// Default to file.
f->type = RFILE;
Expand Down Expand Up @@ -440,21 +444,24 @@ static int recursive_browser_token_match(const Mode *sw,
}

static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
unsigned int height, guint scale) {
unsigned int height) {
FileBrowserModePrivateData *pd =
(FileBrowserModePrivateData *)mode_get_private_data(sw);
const guint scale = display_scale();
g_return_val_if_fail(pd->array != NULL, NULL);
FBFile *dr = &(pd->array[selected_line]);
if (dr->icon_fetch_uid > 0 && dr->icon_fetch_size == height) {
if (dr->icon_fetch_uid > 0 && dr->icon_fetch_size == height &&
dr->icon_fetch_scale == scale) {
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
if (rofi_icon_fetcher_file_is_image(dr->path)) {
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->path, height, scale);
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->path, height);
} else {
dr->icon_fetch_uid =
rofi_icon_fetcher_query(rb_icon_name[dr->type], height, scale);
rofi_icon_fetcher_query(rb_icon_name[dr->type], height);
}
dr->icon_fetch_size = height;
dr->icon_fetch_scale = scale;
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}

Expand Down
9 changes: 5 additions & 4 deletions source/modes/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <sys/types.h>
#include <unistd.h>

#include "display.h"
#include "helper.h"
#include "history.h"
#include "modes/filebrowser.h"
Expand Down Expand Up @@ -538,11 +539,11 @@ static char *run_get_message(const Mode *sw) {
return NULL;
}
static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
unsigned int height, guint scale) {
unsigned int height) {
RunModePrivateData *pd = (RunModePrivateData *)mode_get_private_data(sw);
const guint scale = display_scale();
if (pd->file_complete) {
return pd->completer->_get_icon(pd->completer, selected_line, height,
scale);
return pd->completer->_get_icon(pd->completer, selected_line, height);
}
g_return_val_if_fail(pd->cmd_list != NULL, NULL);
RunEntry *dr = &(pd->cmd_list[selected_line]);
Expand All @@ -555,7 +556,7 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
/** lookup icon */
char **str = g_strsplit(dr->entry, " ", 2);
if (str) {
dr->icon_fetch_uid = rofi_icon_fetcher_query(str[0], height, scale);
dr->icon_fetch_uid = rofi_icon_fetcher_query(str[0], height);
dr->icon_fetch_size = height;
dr->icon_fetch_scale = scale;
g_strfreev(str);
Expand Down
6 changes: 4 additions & 2 deletions source/modes/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define G_LOG_DOMAIN "Modes.Script"

#include "modes/script.h"
#include "display.h"
#include "helper.h"
#include "rofi.h"
#include <assert.h>
Expand Down Expand Up @@ -481,9 +482,10 @@ static char *script_get_message(const Mode *sw) {
}
static cairo_surface_t *script_get_icon(const Mode *sw,
unsigned int selected_line,
unsigned int height, guint scale) {
unsigned int height) {
ScriptModePrivateData *pd =
(ScriptModePrivateData *)mode_get_private_data(sw);
const guint scale = display_scale();
g_return_val_if_fail(pd->cmd_list != NULL, NULL);
DmenuScriptEntry *dr = &(pd->cmd_list[selected_line]);
if (dr->icon_name == NULL) {
Expand All @@ -493,7 +495,7 @@ static cairo_surface_t *script_get_icon(const Mode *sw,
dr->icon_fetch_scale == scale) {
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
}
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->icon_name, height, scale);
dr->icon_fetch_uid = rofi_icon_fetcher_query(dr->icon_name, height);
dr->icon_fetch_size = height;
dr->icon_fetch_scale = scale;
return rofi_icon_fetcher_get(dr->icon_fetch_uid);
Expand Down
6 changes: 4 additions & 2 deletions source/modes/wayland-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <glib.h>
#include <wayland-client.h>

#include "display.h"
#include "helper.h"
#include "modes/wayland-window.h"
#include "rofi.h"
Expand Down Expand Up @@ -572,9 +573,10 @@ static char *_get_display_value(const Mode *sw, unsigned int selected_line,
}

static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
unsigned int height, guint scale) {
unsigned int height) {
WaylandWindowModePrivateData *pd =
(WaylandWindowModePrivateData *)mode_get_private_data(sw);
const guint scale = display_scale();

g_return_val_if_fail(pd != NULL, NULL);

Expand All @@ -600,7 +602,7 @@ static cairo_surface_t *_get_icon(const Mode *sw, unsigned int selected_line,
gchar *app_id_lower = g_utf8_strdown(toplevel->app_id, -1);
toplevel->cached_icon_size = height;
toplevel->cached_icon_scale = scale;
toplevel->cached_icon_uid = rofi_icon_fetcher_query(app_id_lower, height, scale);
toplevel->cached_icon_uid = rofi_icon_fetcher_query(app_id_lower, height);
g_free(app_id_lower);

return rofi_icon_fetcher_get(toplevel->cached_icon_uid);
Expand Down
Loading