-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[gtk] Split the libadwaita/libhandy code into a separate file.
pfn_adwaita.c handles all of the dlopen() functionality and uses either adw_* or hdy_* depending on the GTK version in use. It's built for GTK3 and GTK4, but not for GTK2. Effectively no user-visible changes.
- Loading branch information
1 parent
6162805
commit 68c2082
Showing
7 changed files
with
173 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/*************************************************************************** | ||
* ROM Properties Page shell extension. (GTK+ common) * | ||
* pfn_adwaita.c: libadwaita/libhandy function pointer handling. * | ||
* * | ||
* Copyright (c) 2017-2025 by David Korth. * | ||
* SPDX-License-Identifier: GPL-2.0-or-later * | ||
***************************************************************************/ | ||
|
||
#include "stdafx.h" | ||
#include "config.gtk.h" | ||
#include "pfn_adwaita.h" | ||
|
||
// libdl | ||
#ifdef HAVE_DLVSYM | ||
# ifndef _GNU_SOURCE | ||
# define _GNU_SOURCE 1 | ||
# endif /* _GNU_SOURCE */ | ||
#else /* !HAVE_DLVSYM */ | ||
# define dlvsym(handle, symbol, version) dlsym((handle), (symbol)) | ||
#endif /* HAVE_DLVSYM */ | ||
#include <dlfcn.h> | ||
|
||
// libadwaita/libhandy function pointers. | ||
// Only initialized if libadwaita/libhandy is linked into the process. | ||
// NOTE: The function pointers are essentially the same, but | ||
// libhandy was renamed to libadwaita for the GTK4 conversion. | ||
// We'll use libadwaita terminology everywhere. | ||
|
||
static gsize has_checked_adw = 0; | ||
pfnGlibGetType_t pfn_adw_deck_get_type = NULL; | ||
pfnGlibGetType_t pfn_adw_header_bar_get_type = NULL; | ||
pfnAdwHeaderBarPackEnd_t pfn_adw_header_bar_pack_end = NULL; | ||
|
||
#if GTK_CHECK_VERSION(4,0,0) | ||
// GTK4: libadwaita | ||
# define ADW_SYM_PREFIX "adw_" | ||
# define ADW_SYM_VERSION "LIBADWAITA_1_0" | ||
#else /* !GTK_CHECK_VERSION(4,0,0) */ | ||
// GTK3: libhandy | ||
# define ADW_SYM_PREFIX "hdy_" | ||
# define ADW_SYM_VERSION "LIBHANDY_1_0" | ||
#endif | ||
|
||
/** | ||
* Initialize libadwaita/libhandy function pointers. | ||
* @return TRUE on success; FALSE on failure. | ||
*/ | ||
gboolean rp_init_pfn_adwaita(void) | ||
{ | ||
if (g_once_init_enter(&has_checked_adw)) { | ||
// Check if libadwaita-1 is loaded in the process. | ||
// TODO: Verify that it is in fact 1.x if symbol versioning isn't available. | ||
pfn_adw_deck_get_type = (pfnGlibGetType_t)dlvsym( | ||
RTLD_DEFAULT, ADW_SYM_PREFIX "deck_get_type", ADW_SYM_VERSION); | ||
if (pfn_adw_deck_get_type) { | ||
pfn_adw_header_bar_get_type = (pfnGlibGetType_t)dlvsym( | ||
RTLD_DEFAULT, ADW_SYM_PREFIX "header_bar_get_type", ADW_SYM_VERSION); | ||
pfn_adw_header_bar_pack_end = (pfnAdwHeaderBarPackEnd_t)dlvsym( | ||
RTLD_DEFAULT, ADW_SYM_PREFIX "header_bar_pack_end", ADW_SYM_VERSION); | ||
} | ||
|
||
g_once_init_leave(&has_checked_adw, 1); | ||
} | ||
|
||
return (pfn_adw_deck_get_type != NULL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/*************************************************************************** | ||
* ROM Properties Page shell extension. (GTK+ common) * | ||
* pfn_adwaita.h: libadwaita/libhandy function pointer handling. * | ||
* * | ||
* Copyright (c) 2017-2025 by David Korth. * | ||
* SPDX-License-Identifier: GPL-2.0-or-later * | ||
***************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include "gtk-compat.h" | ||
|
||
G_BEGIN_DECLS | ||
|
||
// libadwaita/libhandy function pointers. | ||
// Only initialized if libadwaita/libhandy is linked into the process. | ||
// NOTE: The function pointers are essentially the same, but | ||
// libhandy was renamed to libadwaita for the GTK4 conversion. | ||
// We'll use libadwaita terminology everywhere. | ||
typedef struct _AdwHeaderBar AdwHeaderBar; | ||
typedef GType (*pfnGlibGetType_t)(void); | ||
typedef void (*pfnAdwHeaderBarPackEnd_t)(AdwHeaderBar *self, GtkWidget *child); | ||
|
||
#if GTK_CHECK_VERSION(3,0,0) | ||
# define RP_MAY_HAVE_ADWAITA 1 | ||
|
||
extern pfnGlibGetType_t pfn_adw_deck_get_type; | ||
extern pfnGlibGetType_t pfn_adw_header_bar_get_type; | ||
extern pfnAdwHeaderBarPackEnd_t pfn_adw_header_bar_pack_end; | ||
|
||
/** | ||
* Initialize libadwaita/libhandy function pointers. | ||
* @return TRUE on success; FALSE on failure. | ||
*/ | ||
gboolean rp_init_pfn_adwaita(void); | ||
|
||
#else /* !GTK_CHECK_VERSION(3,0,0) */ | ||
|
||
// GTK2: No libadwaita/libhandy. | ||
static inline GType pfn_adw_deck_get_type(void) | ||
{ | ||
return 0; | ||
} | ||
static inline GType pfn_adw_header_bar_get_type(void) | ||
{ | ||
return 0; | ||
} | ||
static inline void pfn_adw_header_bar_pack_end(AdwHeaderBar *self, GtkWidget *child) | ||
{ | ||
((void)self); | ||
((void)child); | ||
} | ||
|
||
/** | ||
* Initialize libadwaita/libhandy function pointers. | ||
* @return TRUE on success; FALSE on failure. | ||
*/ | ||
static inline gboolean rp_init_pfn_adwaita(void) | ||
{ | ||
return FALSE; | ||
} | ||
|
||
#endif /* GTK_CHECK_VERSION(3,0,0) */ | ||
|
||
G_END_DECLS |