### Compile and Install GTK Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/building.md After configuring the build directory with Meson, use these commands to compile and install GTK. You might need root privileges for installation. ```bash meson compile -Cbuilddir ``` ```bash meson install -Cbuilddir ``` -------------------------------- ### Install GTK Source: https://github.com/gnome/gtk/blob/main/README.md Installs GTK after it has been built, using Meson. This command typically requires superuser privileges. ```sh $ sudo meson install -C_build ``` -------------------------------- ### Configure GTK Build with Meson Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/building.md Use this command to set up the build directory for GTK. The `--prefix` argument specifies the installation location. Ensure Meson and Ninja are installed. ```bash meson setup --prefix /opt/gtk builddir ``` -------------------------------- ### Install GTK Emoji Resource Bundle Source: https://github.com/gnome/gtk/blob/main/gtk/emoji/README.md Indicates the installation path for the GTK emoji resource bundle. ```text /usr/share/gtk-4.0/emoji/de.gresource ``` -------------------------------- ### Widget Action Installation Source: https://github.com/gnome/gtk/blob/main/testsuite/gdk/clipboard-data/test.txt Functions to install actions on a widget class, either as general actions or property-based actions. ```APIDOC ## gtk_widget_class_install_action ### Description Installs a named action on a widget class. When the action is activated, `activate` will be called. ### Method void ### Endpoint N/A (Function Signature) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (N/A) None #### Response Example None ## gtk_widget_class_install_property_action ### Description Installs a named action on a widget class that is linked to a specific property. When the action is activated, the specified property will be toggled. ### Method void ### Endpoint N/A (Function Signature) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (N/A) None #### Response Example None ``` -------------------------------- ### Install GTK Demo Applications Source: https://github.com/gnome/gtk/blob/main/README.md Installs nightly flatpaks for GTK demo applications. Ensure you have added the GNOME Nightly repository first. ```sh flatpak remote-add --if-not-exists gnome-nightly https://nightly.gnome.org/gnome-nightly.flatpakrepo flatpak install gnome-nightly org.gtk.Demo4 flatpak install gnome-nightly org.gtk.WidgetFactory4 flatpak install gnome-nightly org.gtk.IconBrowser4 ``` -------------------------------- ### Install Widget Action Source: https://github.com/gnome/gtk/blob/main/testsuite/gdk/clipboard-data/test.txt Installs a custom action on a widget class. This action can be triggered by name and may have a parameter type. Use this when defining new widget-specific behaviors. ```c typedef void (* GtkWidgetActionActivateFunc) ( GtkWidget *widget, const char *action_name, GVariant *parameter ); GDK_AVAILABLE_IN_ALL void gtk_widget_class_install_action ( GtkWidgetClass *widget_class, const char *action_name, const char *parameter_type, GtkWidgetActionActivateFunc activate ); ``` -------------------------------- ### Implement Application Startup and Actions Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/getting_started.md C code for initializing GTK application startup, adding action entries for menu items, and setting keyboard accelerators. The `startup` vfunc is used for one-time initialization per application instance. ```c ... static void preferences_activated (GSimpleAction *action, GVariant *parameter, gpointer app) { } static void quit_activated (GSimpleAction *action, GVariant *parameter, gpointer app) { g_application_quit (G_APPLICATION (app)); } static GActionEntry app_entries[] = { { "preferences", preferences_activated, NULL, NULL, NULL }, { "quit", quit_activated, NULL, NULL, NULL } }; static void example_app_startup (GApplication *app) { GtkBuilder *builder; GMenuModel *app_menu; const char *quit_accels[2] = { "Q", NULL }; G_APPLICATION_CLASS (example_app_parent_class)->startup (app); g_action_map_add_action_entries (G_ACTION_MAP (app), app_entries, G_N_ELEMENTS (app_entries), app); gtk_application_set_accels_for_action (GTK_APPLICATION (app), "app.quit", quit_accels); } static void example_app_class_init (ExampleAppClass *class) { G_APPLICATION_CLASS (class)->startup = example_app_startup; ... } ... ``` -------------------------------- ### Build GTK with Meson Source: https://github.com/gnome/gtk/blob/main/docs/RELEASE-HOWTO.md Set up the build environment and compile the project using Meson and Ninja. ```shell meson setup _build meson compile -C _build ``` -------------------------------- ### Create a Basic GTK Window Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/getting_started.md This C code creates a simple GTK application with a 200x200 pixel window titled 'Window'. It initializes a GtkApplication, connects the 'activate' signal, and sets up the main window. ```c #include static void activate (GtkApplication *app, gpointer user_data) { GtkWidget *window; window = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (window), "Window"); gtk_window_set_default_size (GTK_WINDOW (window), 200, 200); gtk_window_present (GTK_WINDOW (window)); } int main (int argc, char **argv) { GtkApplication *app; int status; app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS); g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); status = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); return status; } ``` -------------------------------- ### Hex String Image Data Example Source: https://github.com/gnome/gtk/blob/main/docs/reference/gsk/node-format.md An example of providing image data as a literal hex string, ignoring whitespace. Useful for testing and debugging. ```text "FF0000 ff" ``` -------------------------------- ### ExampleApp GtkApplication subclass Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/getting_started.md This code defines the ExampleApp class, a subclass of GtkApplication. It overrides the activate and open virtual functions to handle application startup and file opening, respectively. The example_app_new function creates a new instance with a specific application ID and flags. ```c #include #include "exampleapp.h" #include "exampleappwin.h" struct _ExampleApp { GtkApplication parent; }; G_DEFINE_TYPE(ExampleApp, example_app, GTK_TYPE_APPLICATION); static void example_app_init (ExampleApp *app) { } static void example_app_activate (GApplication *app) { ExampleAppWindow *win; win = example_app_window_new (EXAMPLE_APP (app)); gtk_window_present (GTK_WINDOW (win)); } static void example_app_open (GApplication *app, GFile **files, int n_files, const char *hint) { GList *windows; ExampleAppWindow *win; int i; windows = gtk_application_get_windows (GTK_APPLICATION (app)); if (windows) win = EXAMPLE_APP_WINDOW (windows->data); else win = example_app_window_new (EXAMPLE_APP (app)); for (i = 0; i < n_files; i++) example_app_window_open (win, files[i]); gtk_window_present (GTK_WINDOW (win)); } static void example_app_class_init (ExampleAppClass *class) { G_APPLICATION_CLASS (class)->activate = example_app_activate; G_APPLICATION_CLASS (class)->open = example_app_open; } ExampleApp * example_app_new (void) { return g_object_new (EXAMPLE_APP_TYPE, "application-id", "org.gtk.exampleapp", "flags", G_APPLICATION_HANDLES_OPEN, NULL); } ``` -------------------------------- ### Install Vulkan Support via Homebrew Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/osx.md Install necessary packages for Vulkan support on macOS using Homebrew. This includes the Vulkan loader, shaderc, and MoltenVK. ```sh brew install vulkan-loader shaderc molten-vk ``` -------------------------------- ### Configure GTK Build Options Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/building.md Run this command to see a summary of all supported Meson options and their allowed values for GTK. ```bash meson configure builddir ``` -------------------------------- ### Build GTK with Meson Source: https://github.com/gnome/gtk/blob/main/README.md Sets up the build directory and compiles GTK using Meson. Ensure all dependencies are installed before running. ```sh $ meson setup _build $ meson compile -C_build ``` -------------------------------- ### ExampleAppWindow GtkApplicationWindow subclass Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/getting_started.md This code defines the ExampleAppWindow class, a subclass of GtkApplicationWindow. It provides basic initialization and a constructor function. The example_app_window_open function is a placeholder for handling file opening within the window. ```c #include #include "exampleapp.h" #include "exampleappwin.h" struct _ExampleAppWindow { GtkApplicationWindow parent; }; G_DEFINE_TYPE(ExampleAppWindow, example_app_window, GTK_TYPE_APPLICATION_WINDOW); static void example_app_window_init (ExampleAppWindow *app) { } static void example_app_window_class_init (ExampleAppWindowClass *class) { } ExampleAppWindow * example_app_window_new (ExampleApp *app) { return g_object_new (EXAMPLE_APP_WINDOW_TYPE, "application", app, NULL); } void example_app_window_open (ExampleAppWindow *win, GFile *file) { } ``` -------------------------------- ### Install Property Action Source: https://github.com/gnome/gtk/blob/main/testsuite/gdk/clipboard-data/test.txt Installs an action on a widget class that is linked to a specific widget property. Changes to this property can trigger the action. This is useful for actions that directly manipulate widget properties. ```c GDK_AVAILABLE_IN_ALL void gtk_widget_class_install_property_action ( GtkWidgetClass *widget_class, const char *action_name, const char *property_name ); ``` -------------------------------- ### GTK Icon Theme Cache Hash Function Example Source: https://github.com/gnome/gtk/blob/main/docs/iconcache.txt An example implementation of a string hashing function used for icon lookups in the cache. This function should not be called directly via g_str_hash(). ```c unsigned int icon_str_hash (gconstpointer key) { const char *p = key; unsigned int h = *p; if (h) for (p += 1; *p != '\0'; p++) h = (h << 5) - h + *p; return h; } ``` -------------------------------- ### Setup GtkTreeView with GtkTreeStore Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/section-tree-widget.md Use this snippet to create a GtkTreeView and populate it with data from a GtkTreeStore. Ensure the model is correctly defined with appropriate GType for each column. ```c enum { TITLE_COLUMN, AUTHOR_COLUMN, CHECKED_COLUMN, N_COLUMNS }; void setup_tree (void) { GtkTreeStore *store; GtkWidget *tree; GtkTreeViewColumn *column; GtkCellRenderer *renderer; /* Create a model. We are using the store model for now, though we * could use any other GtkTreeModel */ store = gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN); /* custom function to fill the model with data */ populate_tree_model (store); /* Create a view */ tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); /* The view now holds a reference. We can get rid of our own * reference */ g_object_unref (G_OBJECT (store)); /* Create a cell render and arbitrarily make it red for demonstration * purposes */ renderer = gtk_cell_renderer_text_new (); g_object_set (G_OBJECT (renderer), "foreground", "red", NULL); /* Create a column, associating the "text" attribute of the * cell_renderer to the first column of the model */ column = gtk_tree_view_column_new_with_attributes ("Author", renderer, "text", AUTHOR_COLUMN, NULL); /* Add the column to the view. */ gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); /* Second column.. title of the book. */ renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ("Title", renderer, "text", TITLE_COLUMN, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); /* Last column.. whether a book is checked out. */ renderer = gtk_cell_renderer_toggle_new (); column = gtk_tree_view_column_new_with_attributes ("Checked out", renderer, "active", CHECKED_COLUMN, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column); /* Now we can manipulate the view just like any other GTK widget */ ... } ``` -------------------------------- ### Configure and Compile GTK from Git Source: https://github.com/gnome/gtk/blob/main/CONTRIBUTING.md Set up the build environment using Meson and compile the GTK project from its Git repository. ```sh meson setup _builddir . meson compile -C _builddir ``` -------------------------------- ### JavaScript Status Icon Example with GTK+ Source: https://github.com/gnome/gtk/blob/main/demos/gtk-demo/messages.txt An example demonstrating how to implement a status icon using JavaScript and GTK+. This snippet is useful for developers looking to integrate GTK+ functionality into their JavaScript applications. ```javascript This is the official GTK+ first micropost! ``` -------------------------------- ### C++ Signal Connection Example Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/question_index.md When using GTK directly in C++, signal connections must use global or static class functions, not methods. This example shows the correct syntax for connecting a signal. ```c gdk_surface_set_events (gdk_surface, (GdkEventMask) GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); ``` -------------------------------- ### Desktop Entry File Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/getting_started.md This is a sample .desktop file for a GTK application. It defines the application's metadata, including its name, icon, and executable path. The @bindir@ placeholder needs to be replaced with the actual binary directory path. ```desktop [Desktop Entry] Type=Application Name=Example Icon=exampleapp StartupNotify=true Exec=@bindir@/exampleapp ``` -------------------------------- ### Get GtkTextView Content as String Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/question_index.md Use this snippet to retrieve the entire text content of a GtkTextView widget. It involves getting the text buffer, its bounds, and then the text itself. Remember to free the allocated string after use. ```c GtkTextIter start, end; GtkTextBuffer *buffer; char *text; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view)); gtk_text_buffer_get_bounds (buffer, &start, &end); text = gtk_text_iter_get_text (&start, &end); /* use text */ g_free (text); ``` -------------------------------- ### Upload Tarball and Install via Ftpadmin Source: https://github.com/gnome/gtk/blob/main/docs/RELEASE-HOWTO.md Upload the release tarball to the master server and use ftpadmin to transfer it to the download server. Requires an account on master.gnome.org. ```shell scp gtk-4.2.0.tar.xz matthiasc@master.gnome.org: ssh matthiasc@master.gnome.org ftpadmin install gtk-4.2.0.tar.xz ``` -------------------------------- ### Start the Broadway server Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/broadway.md Run the `gtk-broadwayd` server, specifying the display number prefixed with a colon. ```bash gtk4-broadwayd :5 ``` -------------------------------- ### Cursor Management Source: https://github.com/gnome/gtk/blob/main/testsuite/gdk/clipboard-data/test.txt Functions to set and get the cursor for a widget. ```APIDOC ## void gtk_widget_set_cursor ### Description Sets the cursor for the widget. ### Method void ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## void gtk_widget_set_cursor_from_name ### Description Sets the cursor for the widget using a cursor name. ### Method void ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## GdkCursor *gtk_widget_get_cursor ### Description Retrieves the cursor of the widget. ### Method GdkCursor * ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) GdkCursor * - The widget's cursor. #### Response Example N/A ``` -------------------------------- ### Widget Settings Source: https://github.com/gnome/gtk/blob/main/testsuite/gdk/clipboard-data/test.txt Gets the GtkSettings associated with a GTK widget. ```APIDOC ## gtk_widget_get_settings ### Description Gets the `GtkSettings` object that controls the widget's appearance and behavior. ### Method GtkSettings* ### Parameters - **widget** (GtkWidget*) - The widget to query. ### Returns The `GtkSettings` object for the widget. ``` -------------------------------- ### Initialize GtkTextView and Set Text Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/section-text-widget.md Demonstrates the basic steps to create a GtkTextView widget, get its text buffer, and set initial text content. This is useful for simple text display. ```c GtkWidget *view; GtkTextBuffer *buffer; view = gtk_text_view_new (); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); gtk_text_buffer_set_text (buffer, "Hello, this is some text", -1); /* Now you might put the view in a container and display it on the * screen; when the user edits the text, signals on the buffer * will be emitted, such as "changed", "insert_text", and so on. */ ``` -------------------------------- ### Widget Display Source: https://github.com/gnome/gtk/blob/main/testsuite/gdk/clipboard-data/test.txt Gets the GdkDisplay associated with a GTK widget. ```APIDOC ## gtk_widget_get_display ### Description Gets the `GdkDisplay` to which the widget belongs. ### Method GdkDisplay* ### Parameters - **widget** (GtkWidget*) - The widget to query. ### Returns The `GdkDisplay` of the widget. ``` -------------------------------- ### Tooltip Management Source: https://github.com/gnome/gtk/blob/main/testsuite/gdk/clipboard-data/test.txt Functions for setting and getting tooltip information for a widget. ```APIDOC ## void gtk_widget_trigger_tooltip_query ### Description Triggers a tooltip query for the widget. ### Method void ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## void gtk_widget_set_tooltip_text ### Description Sets the tooltip text for the widget. ### Method void ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## const char *gtk_widget_get_tooltip_text ### Description Retrieves the tooltip text of the widget. ### Method const char * ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) const char * - The widget's tooltip text. #### Response Example N/A ## void gtk_widget_set_tooltip_markup ### Description Sets the tooltip markup for the widget. ### Method void ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## const char *gtk_widget_get_tooltip_markup ### Description Retrieves the tooltip markup of the widget. ### Method const char * ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) const char * - The widget's tooltip markup. #### Response Example N/A ## void gtk_widget_set_has_tooltip ### Description Sets whether the widget has a tooltip. ### Method void ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## gboolean gtk_widget_get_has_tooltip ### Description Retrieves whether the widget has a tooltip. ### Method g gboolean ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) gboolean - Whether the widget has a tooltip. #### Response Example N/A ``` -------------------------------- ### Initialize Window Template in C Source: https://github.com/gnome/gtk/blob/main/docs/reference/gtk/getting_started.md These C functions initialize the GtkBuilder template for the `ExampleAppWindow` class. `example_app_window_init` instantiates the template for each window instance, and `example_app_window_class_init` sets the UI file as the template for the class. ```c static void example_app_window_init (ExampleAppWindow *win) { gtk_widget_init_template (GTK_WIDGET (win)); } ``` ```c static void example_app_window_class_init (ExampleAppWindowClass *class) { gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (class), "/org/gtk/exampleapp/window.ui"); } ``` -------------------------------- ### Text Direction Source: https://github.com/gnome/gtk/blob/main/testsuite/gdk/clipboard-data/test.txt Functions to set and get the text directionality for widgets. ```APIDOC ## void gtk_widget_set_direction ### Description Sets the text direction for the widget. ### Method void ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## GtkTextDirection gtk_widget_get_direction ### Description Retrieves the text direction of the widget. ### Method GtkTextDirection ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) GtkTextDirection - The widget's text direction. #### Response Example N/A ## void gtk_widget_set_default_direction ### Description Sets the default text direction for new widgets. ### Method void ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## GtkTextDirection gtk_widget_get_default_direction ### Description Retrieves the default text direction. ### Method GtkTextDirection ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) GtkTextDirection - The default text direction. #### Response Example N/A ``` -------------------------------- ### Font Options Source: https://github.com/gnome/gtk/blob/main/testsuite/gdk/clipboard-data/test.txt Functions to set and get font options for a widget. ```APIDOC ## void gtk_widget_set_font_options ### Description Sets the font options for the widget. ### Method void ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ## const cairo_font_options_t *gtk_widget_get_font_options ### Description Retrieves the font options for the widget. ### Method const cairo_font_options_t * ### Endpoint N/A (Function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) const cairo_font_options_t * - The widget's font options. #### Response Example N/A ``` -------------------------------- ### Methods Documentation Source: https://github.com/gnome/gtk/blob/main/docs/reference/README.md Guidelines for documenting methods in GTK. ```APIDOC ## Methods Documentation ### Description Methods are special functions whose first argument is always the instance of a certain class. The instance argument for newly written code should be called `self`. If a method is a setter or a getter for an object property `GtkClassName:prop-name`, and if its name does not match the naming scheme `gtk_class_name_{g,s}et_prop_name`, you should add a `(set-property prop-name)` or a `(get-property prop-name)` annotation to the method's identifier. If a method changes one or more properties as side effect, link those properties in the method's description. If a method is a signal emitter, you should use the `(attributes org.gtk.Method.signal=signal-name)` annotation in the method's identifier. ``` -------------------------------- ### Widget Clipboard Source: https://github.com/gnome/gtk/blob/main/testsuite/gdk/clipboard-data/test.txt Functions to get the GdkClipboard associated with a GTK widget. ```APIDOC ## gtk_widget_get_clipboard ### Description Gets the default `GdkClipboard` for the widget. ### Method GdkClipboard* ### Parameters - **widget** (GtkWidget*) - The widget to query. ### Returns The default `GdkClipboard`. ## gtk_widget_get_primary_clipboard ### Description Gets the primary `GdkClipboard` for the widget. ### Method GdkClipboard* ### Parameters - **widget** (GtkWidget*) - The widget to query. ### Returns The primary `GdkClipboard`. ```