GTK4: Don't require use of MenuButton.set_child introduced with 4.6

This commit is contained in:
Marvin W 2022-08-21 00:57:03 +02:00
parent 7b252d040a
commit d6afa6e8ff
No known key found for this signature in database
GPG key ID: 072E9235DB996F2A
3 changed files with 25 additions and 3 deletions

View file

@ -179,7 +179,6 @@ endif (NOT NO_DEBUG)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(GTK3_GLOBAL_VERSION 3.22)
set(GLib_GLOBAL_VERSION 2.38) set(GLib_GLOBAL_VERSION 2.38)
set(ICU_GLOBAL_VERSION 57) set(ICU_GLOBAL_VERSION 57)

View file

@ -3,6 +3,7 @@ find_package(Gettext)
include(${GETTEXT_USE_FILE}) include(${GETTEXT_USE_FILE})
gettext_compile(${GETTEXT_PACKAGE} SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/po TARGET_NAME ${GETTEXT_PACKAGE}-translations) gettext_compile(${GETTEXT_PACKAGE} SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/po TARGET_NAME ${GETTEXT_PACKAGE}-translations)
find_package(GTK4 REQUIRED)
find_packages(MAIN_PACKAGES REQUIRED find_packages(MAIN_PACKAGES REQUIRED
Gee Gee
GLib GLib
@ -104,6 +105,11 @@ unset(MAIN_EXTRA_OPTIONS)
unset(MAIN_EXTRA_PACKAGES) unset(MAIN_EXTRA_PACKAGES)
set(MAIN_EXTRA_OPTIONS ${MAIN_EXTRA_OPTIONS} --vapidir=${CMAKE_CURRENT_SOURCE_DIR}/vapi) set(MAIN_EXTRA_OPTIONS ${MAIN_EXTRA_OPTIONS} --vapidir=${CMAKE_CURRENT_SOURCE_DIR}/vapi)
set(MAIN_DEFINITIONS)
if(GTK4_VERSION VERSION_GREATER_EQUAL "4.6")
set(MAIN_DEFINITIONS ${MAIN_DEFINITIONS} GTK_4_6)
endif()
vala_precompile(MAIN_VALA_C vala_precompile(MAIN_VALA_C
SOURCES SOURCES
src/main.vala src/main.vala
@ -200,6 +206,8 @@ PACKAGES
${MAIN_EXTRA_PACKAGES} ${MAIN_EXTRA_PACKAGES}
GRESOURCES GRESOURCES
${MAIN_GRESOURCES_XML} ${MAIN_GRESOURCES_XML}
DEFINITIONS
${MAIN_DEFINITIONS}
OPTIONS OPTIONS
${MAIN_EXTRA_OPTIONS} ${MAIN_EXTRA_OPTIONS}
) )

View file

@ -37,7 +37,7 @@ public class Dino.Ui.CallBottomBar : Gtk.Box {
audio_button.margin_end = audio_button.margin_bottom = 5; // space for the small settings button audio_button.margin_end = audio_button.margin_bottom = 5; // space for the small settings button
audio_button_overlay.set_child(audio_button); audio_button_overlay.set_child(audio_button);
audio_button_overlay.add_overlay(audio_settings_button); audio_button_overlay.add_overlay(audio_settings_button);
audio_settings_button.set_child(new Image.from_icon_name("go-up-symbolic") { pixel_size=10 }); menu_button_set_icon_with_size(audio_settings_button, "go-up-symbolic", 10);
audio_settings_button.add_css_class("call-mediadevice-settings-button"); audio_settings_button.add_css_class("call-mediadevice-settings-button");
main_buttons.append(audio_button_overlay); main_buttons.append(audio_button_overlay);
@ -47,7 +47,7 @@ public class Dino.Ui.CallBottomBar : Gtk.Box {
video_button.margin_end = video_button.margin_bottom = 5; video_button.margin_end = video_button.margin_bottom = 5;
video_button_overlay.set_child(video_button); video_button_overlay.set_child(video_button);
video_button_overlay.add_overlay(video_settings_button); video_button_overlay.add_overlay(video_settings_button);
video_settings_button.set_child(new Image.from_icon_name("go-up-symbolic") { pixel_size=10 }); menu_button_set_icon_with_size(video_settings_button, "go-up-symbolic", 10);
video_settings_button.add_css_class("call-mediadevice-settings-button"); video_settings_button.add_css_class("call-mediadevice-settings-button");
main_buttons.append(video_button_overlay); main_buttons.append(video_button_overlay);
@ -76,6 +76,21 @@ public class Dino.Ui.CallBottomBar : Gtk.Box {
this.add_css_class("call-bottom-bar"); this.add_css_class("call-bottom-bar");
} }
private static void menu_button_set_icon_with_size(MenuButton menu_button, string icon_name, int pixel_size) {
#if GTK_4_6
menu_button.set_child(new Image.from_icon_name(icon_name) { pixel_size=pixel_size });
#else
menu_button.set_icon_name(icon_name);
var button = menu_button.get_first_child() as Button;
if (button == null) return;
var box = button.child as Box;
if (box == null) return;
var image = box.get_first_child() as Image;
if (image == null) return;
image.pixel_size = pixel_size;
#endif
}
public AudioSettingsPopover? show_audio_device_choices(bool show) { public AudioSettingsPopover? show_audio_device_choices(bool show) {
audio_settings_button.visible = show; audio_settings_button.visible = show;
if (audio_settings_popover != null) audio_settings_popover.visible = false; if (audio_settings_popover != null) audio_settings_popover.visible = false;