Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
gtk.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2018-2024 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __UTILS_GTK_H__
11#define __UTILS_GTK_H__
12
13#include "zrythm-config.h"
14
15#include "gtk_wrapper.h"
16
17G_GNUC_BEGIN_IGNORE_DEPRECATIONS
18#include <gtksourceview/gtksource.h>
19G_GNUC_END_IGNORE_DEPRECATIONS
20
27#define DEFAULT_CLIPBOARD gdk_display_get_clipboard (gdk_display_get_default ())
28
29#define CREATE_MIDI_LEARN_MENU_ITEM(action) \
30 z_gtk_create_menu_item (_ ("MIDI learn"), "signal-midi", action)
31
32#define CREATE_CUT_MENU_ITEM(action) \
33 z_gtk_create_menu_item (_ ("Cu_t"), "edit-cut", action)
34
35#define CREATE_COPY_MENU_ITEM(action) \
36 z_gtk_create_menu_item (_ ("_Copy"), "edit-copy", action)
37
38#define CREATE_PASTE_MENU_ITEM(action) \
39 z_gtk_create_menu_item (_ ("_Paste"), "edit-paste", action)
40
41#define CREATE_DELETE_MENU_ITEM(action) \
42 z_gtk_create_menu_item (_ ("_Delete"), "edit-delete", action)
43
44#define CREATE_CLEAR_SELECTION_MENU_ITEM(action) \
45 z_gtk_create_menu_item (/* TRANSLATORS: deselects everything */ \
46 _ ("Cle_ar Selection"), "edit-clear", action)
47
48#define CREATE_SELECT_ALL_MENU_ITEM(action) \
49 z_gtk_create_menu_item (_ ("Select A_ll"), "edit-select-all", action)
50
51#define CREATE_DUPLICATE_MENU_ITEM(action) \
52 z_gtk_create_menu_item (_ ("Duplicate"), "edit-duplicate", action)
53
54#define CREATE_MUTE_MENU_ITEM(action) \
55 z_gtk_create_menu_item (_ ("Mute"), "mute", action)
56
57#define CREATE_UNMUTE_MENU_ITEM(action) \
58 z_gtk_create_menu_item (_ ("Unmute"), NULL, action)
59
60#define z_gtk_assistant_set_current_page_complete(assistant, complete) \
61 gtk_assistant_set_page_complete ( \
62 GTK_ASSISTANT (assistant), \
63 gtk_assistant_get_nth_page ( \
64 GTK_ASSISTANT (assistant), \
65 gtk_assistant_get_current_page (GTK_ASSISTANT (assistant))), \
66 complete);
67
68#define Z_GDK_RGBA_INIT(r, g, b, a) \
69 { \
70 .red = static_cast<float> (r), .green = static_cast<float> (g), \
71 .blue = static_cast<float> (b), .alpha = static_cast<float> (a) \
72 }
73
74#define Z_GDK_RECTANGLE_INIT(_x, _y, _w, _h) \
75 { \
76 .x = _x, .y = _y, .width = _w, .height = _h \
77 }
78
79#define Z_GDK_RECTANGLE_INIT_UNIT(_x, _y) \
80 { \
81 .x = _x, .y = _y, .width = 1, .height = 1 \
82 }
83
84#define Z_GRAPHENE_RECT_INIT(_x, _y, _w, _h) \
85 GRAPHENE_RECT_INIT ( \
86 static_cast<float> (_x), static_cast<float> (_y), static_cast<float> (_w), \
87 static_cast<float> (_h))
88
89#define Z_GRAPHENE_POINT_INIT(_x, _y) \
90 GRAPHENE_POINT_INIT (static_cast<float> (_x), static_cast<float> (_y))
91
96typedef struct _ZGObjectImpl
97{
98 GTypeInstance g_type_instance;
99
100 /*< private >*/
101 guint ref_count; /* (atomic) */
102 GData * qdata;
104
105enum ZGtkResize
106{
107 Z_GTK_NO_RESIZE,
108 Z_GTK_RESIZE
109};
110
111enum ZGtkShrink
112{
113 Z_GTK_NO_SHRINK,
114 Z_GTK_SHRINK
115};
116
117static inline GtkWidget *
118z_gtk_notebook_get_current_page_widget (GtkNotebook * notebook)
119{
120 return gtk_notebook_get_nth_page (
121 notebook, gtk_notebook_get_current_page (notebook));
122}
123
124static inline GtkWidget *
125z_gtk_notebook_get_current_tab_label_widget (GtkNotebook * notebook)
126{
127 return gtk_notebook_get_tab_label (
128 notebook, z_gtk_notebook_get_current_page_widget (notebook));
129}
130
131GdkMonitor *
132z_gtk_get_primary_monitor (void);
133
134int
135z_gtk_get_primary_monitor_scale_factor (void);
136
137int
138z_gtk_get_primary_monitor_refresh_rate (void);
139
140bool
141z_gtk_is_wayland (void);
142
143void
144z_gtk_tree_view_remove_all_columns (GtkTreeView * treeview);
145
146void
147z_gtk_column_view_remove_all_columnes (GtkColumnView * column_view);
148
149GListStore *
150z_gtk_column_view_get_list_store (GtkColumnView * column_view);
151
156void
157z_gtk_list_store_splice (GListStore * store, GPtrArray * ptr_array);
158
159void
160z_gtk_widget_remove_all_children (GtkWidget * widget);
161
162void
163z_gtk_widget_destroy_all_children (GtkWidget * widget);
164
165void
166z_gtk_widget_remove_children_of_type (GtkWidget * widget, GType type);
167
168void
169z_gtk_overlay_add_if_not_exists (GtkOverlay * overlay, GtkWidget * widget);
170
174void
176 GtkButton * btn,
177 const char * name,
178 const char * text,
179 bool icon_first,
180 GtkOrientation orientation,
181 int spacing);
182
186GtkToggleButton *
188
192GtkToggleButton *
194 const char * name,
195 const char * text,
196 bool icon_first,
197 GtkOrientation orientation,
198 int spacing);
199
204GtkButton *
206 const char * name,
207 const char * text,
208 bool icon_first,
209 GtkOrientation orientation,
210 int spacing);
211
212#define z_gtk_create_menu_item(lbl_name, icn_name, action_name) \
213 z_gtk_create_menu_item_full (lbl_name, icn_name, action_name)
214
218GMenuItem *
220 const gchar * label_name,
221 const gchar * icon_name,
222 const char * detailed_action);
223
234char *
235z_gtk_get_tooltip_for_action (const char * detailed_action, const char * tooltip);
236
244void
246 GtkWidget * widget,
247 const char * detailed_action,
248 const char * tooltip);
249
254void
256 GtkActionable * actionable,
257 const char * tooltip);
258
259#if 0
263void
264z_gtk_tool_button_set_icon_size (
265 GtkToolButton * toolbutton,
266 GtkIconSize icon_size);
267#endif
268
272static inline GdkDevice *
273z_gtk_widget_get_device (GtkWidget * widget)
274{
275 return (gdk_seat_get_pointer (
276 gdk_display_get_default_seat (gtk_widget_get_display (widget))));
277}
278
279#if 0
280static inline GdkWindow *
281z_gtk_widget_get_root_gdk_window (
282 GtkWidget * widget)
283{
284 GdkScreen * screen =
285 z_gtk_widget_get_screen (widget);
286 return
287 gdk_screen_get_root_window (screen);
288}
289#endif
290
291#if 0
292static inline void
293z_gtk_widget_get_global_coordinates (
294 GtkWidget * widget,
295 int * x,
296 int * y)
297{
298 GdkDevice * dev =
299 z_gtk_widget_get_device (widget);
300 GdkWindow * win =
301 z_gtk_widget_get_root_gdk_window (widget);
302 gdk_window_get_device_position (
303 win, dev, x, y, NULL);
304}
305
306static inline void
307z_gtk_widget_get_global_coordinates_double (
308 GtkWidget * widget,
309 double * x,
310 double * y)
311{
312 GdkDevice * dev =
313 z_gtk_widget_get_device (widget);
314 GdkWindow * win =
315 z_gtk_widget_get_root_gdk_window (widget);
316 gdk_window_get_device_position_double (
317 win, dev, x, y, NULL);
318}
319
323static inline void
324z_gtk_warp_cursor_to (
325 GtkWidget * widget, int x, int y)
326{
327 GdkDevice * dev =
328 z_gtk_widget_get_device (widget);
329 GdkScreen * screen =
330 z_gtk_widget_get_screen (widget);
331 gdk_device_warp (dev, screen, x, y);
332}
333#endif
334
335static inline GdkSurface *
336z_gtk_widget_get_surface (GtkWidget * widget)
337{
338 GtkNative * native = gtk_widget_get_native (widget);
339 return gtk_native_get_surface (native);
340}
341
348static inline void
349z_gtk_widget_get_mask (GtkWidget * widget, GdkModifierType * mask)
350{
351 gdk_surface_get_device_position (
352 z_gtk_widget_get_surface (widget), z_gtk_widget_get_device (widget), NULL,
353 NULL, mask);
354}
355
359static inline int
360z_gtk_keyval_is_alt (const guint keyval)
361{
362 return keyval == GDK_KEY_Alt_L || keyval == GDK_KEY_Alt_R
363 || keyval == GDK_KEY_Meta_L || keyval == GDK_KEY_Meta_R;
364}
365
369static inline int
370z_gtk_keyval_is_ctrl (const guint keyval)
371{
372 return keyval == GDK_KEY_Control_L || keyval == GDK_KEY_Control_R;
373}
374
378static inline int
379z_gtk_keyval_is_arrow (const guint keyval)
380{
381 return keyval == GDK_KEY_Left || keyval == GDK_KEY_Right
382 || keyval == GDK_KEY_Down || keyval == GDK_KEY_Up;
383}
384
388static inline int
389z_gtk_keyval_is_shift (const guint keyval)
390{
391 return keyval == GDK_KEY_Shift_L || keyval == GDK_KEY_Shift_R;
392}
393
394static inline int
395z_gtk_keyval_is_menu (const guint keyval)
396{
397 return keyval == GDK_KEY_Menu;
398}
399
403GtkWidget *
404z_gtk_widget_get_nth_child (GtkWidget * widget, int index);
405
410void
411z_gtk_button_set_emblem (GtkButton * btn, const char * emblem_icon);
412
419void
420z_gtk_setup_foldable_notebook (GtkNotebook * notebook);
421
425void
426z_gtk_widget_set_margin (GtkWidget * widget, int margin);
427
428GtkFlowBoxChild *
429z_gtk_flow_box_get_selected_child (GtkFlowBox * self);
430
434bool
435z_gtk_activate_dir_link_func (GtkLabel * label, char * uri, void * data);
436
437GtkSourceLanguageManager *
438z_gtk_source_language_manager_get (void);
439
444void
446 GtkNotebook * notebook,
447 GtkWindow * parent_window);
448
455char *
456z_gtk_text_buffer_get_full_text (GtkTextBuffer * buffer);
457
471void
473 GtkWidget * widget,
474 const char * type,
475 char ** option_keys,
476 char ** option_values,
477 char ** ret_dir,
478 char ** ret_path,
479 bool accept_fallback);
480
488void
490 GtkActionable * actionable,
491 GSettings * settings,
492 const char * key);
493
494bool
495z_gtk_is_event_button (GdkEvent * ev);
496
501void
503 GtkScrolledWindow * scroll,
504 graphene_rect_t * rect);
505
506void
507z_gtk_graphene_rect_t_to_gdk_rectangle (
508 GdkRectangle * rect,
509 graphene_rect_t * grect);
510
511void
512z_gdk_rectangle_to_graphene_rect_t (graphene_rect_t * grect, GdkRectangle * rect);
513
514void
515z_gdk_rectangle_print (const GdkRectangle * rect);
516
524int
525z_gtk_dialog_run (GtkDialog * dialog, bool destroy_on_close);
526
533void
535 GtkPopoverMenu * popover_menu,
536 double x,
537 double y,
538 GMenu * menu);
539
544GdkDragAction
545z_gtk_drop_target_get_selected_action (GtkDropTarget * drop_target);
546
547GtkIconTheme *
548z_gtk_icon_theme_get_default (void);
549
556char *
557z_gdk_clipboard_get_text (GdkClipboard * clipboard);
558
559#ifdef HAVE_X11
560Window
561z_gtk_window_get_x11_xid (GtkWindow * window);
562#endif
563
564#ifdef _WIN32
565HWND
566z_gtk_window_get_windows_hwnd (GtkWindow * window);
567#endif
568
569#ifdef __APPLE__
570void *
571z_gtk_window_get_nsview (GtkWindow * window);
572#endif
573
581GdkPixbuf *
583 const char * icon_name,
584 int width,
585 int height,
586 int scale,
587 GError ** error);
588
596GdkTexture *
598 const char * icon_name,
599 int width,
600 int height,
601 int scale);
602
603void
604z_gtk_print_graphene_rect (graphene_rect_t * rect);
605
609void
610z_gtk_widget_print_hierarchy (GtkWidget * widget);
611
612const char *
613z_gtk_get_gsk_renderer_type (void);
614
621gboolean
623 GtkWidget * widget,
624 GVariant * args,
625 gpointer user_data);
626
631GtkWidget *
632z_gtk_widget_find_child_of_type (GtkWidget * widget, GType type);
633
634void
635z_gtk_list_box_remove_all_children (GtkListBox * list_box);
636
637void
638z_graphene_rect_print (const graphene_rect_t * rect);
639
640GtkStringList *
641z_gtk_string_list_new_from_string_array (
642 const char ** strvals,
643 size_t num_vals,
644 bool localized);
645
646GtkWidget *
647z_gtk_get_first_focusable_child (GtkWidget * parent);
648
649bool
650z_gtk_descendant_has_focus (GtkWidget * parent);
651
652void
653z_gtk_window_make_escapable (GtkWindow * self);
654
658void
660 GtkSignalListItemFactory * factory,
661 GObject * list_item,
662 gpointer user_data);
663
664void
665z_gtk_drop_down_factory_setup_common (
666 GtkSignalListItemFactory * factory,
667 GObject * list_item,
668 gpointer user_data);
669
670void
671z_gtk_drop_down_factory_setup_common_ellipsized (
672 GtkSignalListItemFactory * factory,
673 GObject * list_item,
674 gpointer user_data);
675
676const char *
677z_gtk_get_enum_nick (GType type, gint value);
678
682#endif
void z_gtk_setup_foldable_notebook(GtkNotebook *notebook)
Makes the given notebook foldable.
void z_gtk_generate_screenshot_image(GtkWidget *widget, const char *type, char **option_keys, char **option_values, char **ret_dir, char **ret_path, bool accept_fallback)
Generates a screenshot image for the given widget.
void z_gtk_list_store_splice(GListStore *store, GPtrArray *ptr_array)
Removes all items and re-populates the list store.
void z_gtk_notebook_make_detachable(GtkNotebook *notebook, GtkWindow *parent_window)
Makes the given GtkNotebook detachable to a new window.
bool z_gtk_activate_dir_link_func(GtkLabel *label, char *uri, void *data)
Callback to use for simple directory links.
int z_gtk_dialog_run(GtkDialog *dialog, bool destroy_on_close)
Mimics the blocking behavior.
char * z_gdk_clipboard_get_text(GdkClipboard *clipboard)
Returns the text on the clipboard, or NULL if there is nothing or the content is not text.
void z_gtk_button_set_emblem(GtkButton *btn, const char *emblem_icon)
Sets the given emblem to the button, or unsets the emblem if emblem_icon is NULL.
GtkToggleButton * z_gtk_toggle_button_new_with_icon(const char *name)
Creates a toggle button with the given icon name.
void z_gtk_actionable_set_action_from_setting(GtkActionable *actionable, GSettings *settings, const char *key)
Sets the action target of the given GtkActionable to be binded to the given setting.
void z_gtk_show_context_menu_from_g_menu(GtkPopoverMenu *popover_menu, double x, double y, GMenu *menu)
The popover must already exist as a children of its intended widget (or a common parent).
GtkButton * z_gtk_button_new_with_icon_and_text(const char *name, const char *text, bool icon_first, GtkOrientation orientation, int spacing)
Creates a button with the given icon name and text.
void z_gtk_widget_set_tooltip_for_action(GtkWidget *widget, const char *detailed_action, const char *tooltip)
Sets the tooltip for the given action on the given widget.
void z_gtk_widget_set_margin(GtkWidget *widget, int margin)
Sets the margin on all 4 sides on the widget.
GtkWidget * z_gtk_widget_find_child_of_type(GtkWidget *widget, GType type)
Recursively searches the children of widget for a child of type type.
gboolean z_gtk_simple_action_shortcut_func(GtkWidget *widget, GVariant *args, gpointer user_data)
A shortcut callback to use for simple actions.
GdkTexture * z_gdk_texture_new_from_icon_name(const char *icon_name, int width, int height, int scale)
Creates a new texture for the given icon scaled at the given width/height.
GdkDragAction z_gtk_drop_target_get_selected_action(GtkDropTarget *drop_target)
Returns the bitmask of the selected action during a drop (eg, GDK_ACTION_COPY).
char * z_gtk_get_tooltip_for_action(const char *detailed_action, const char *tooltip)
Gets the tooltip for the given action on the given widget.
GdkPixbuf * z_gdk_pixbuf_new_from_icon_name(const char *icon_name, int width, int height, int scale, GError **error)
Creates a new pixbuf for the given icon scaled at the given width/height.
void z_gtk_drop_down_list_item_header_setup_common(GtkSignalListItemFactory *factory, GObject *list_item, gpointer user_data)
A common "setup" signal handler for GtkDropDown header factories.
GMenuItem * z_gtk_create_menu_item_full(const gchar *label_name, const gchar *icon_name, const char *detailed_action)
Creates a menu item.
void z_gtk_scrolled_window_get_visible_rect(GtkScrolledWindow *scroll, graphene_rect_t *rect)
Gets the visible rectangle from the scrolled window's adjustments.
GtkWidget * z_gtk_widget_get_nth_child(GtkWidget *widget, int index)
Returns the nth child of a container.
void z_gtk_button_set_icon_name_and_text(GtkButton *btn, const char *name, const char *text, bool icon_first, GtkOrientation orientation, int spacing)
Sets the icon name and optionally text.
void z_gtk_widget_print_hierarchy(GtkWidget *widget)
Prints the widget's hierarchy (parents).
void z_gtk_set_tooltip_for_actionable(GtkActionable *actionable, const char *tooltip)
Sets the tooltip and finds the accel keys and appends them to the tooltip in small text.
GtkToggleButton * z_gtk_toggle_button_new_with_icon_and_text(const char *name, const char *text, bool icon_first, GtkOrientation orientation, int spacing)
Creates a toggle button with the given icon name.
char * z_gtk_text_buffer_get_full_text(GtkTextBuffer *buffer)
Returns the full text contained in the text buffer.
GObject struct (from GObject source code), used where hacks are needed.
Definition gtk.h:97