| File: | ctk/ctkapplication.c |
| Warning: | line 487, column 71 Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * Copyright © 2010 Codethink Limited |
| 3 | * Copyright © 2013 Canonical Limited |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the licence, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * Author: Ryan Lortie <desrt@desrt.ca> |
| 19 | */ |
| 20 | |
| 21 | #include "config.h" |
| 22 | |
| 23 | #include "ctkapplication.h" |
| 24 | #include "cdkprivate.h" |
| 25 | |
| 26 | #ifdef G_OS_UNIX |
| 27 | #include <gio/gunixfdlist.h> |
| 28 | #endif |
| 29 | |
| 30 | #include <stdlib.h> |
| 31 | |
| 32 | #ifdef HAVE_UNISTD_H1 |
| 33 | #include <unistd.h> |
| 34 | #endif |
| 35 | |
| 36 | #include "cdk/cdk-private.h" |
| 37 | |
| 38 | #include "ctkapplicationprivate.h" |
| 39 | #include "ctkclipboardprivate.h" |
| 40 | #include "ctkmarshalers.h" |
| 41 | #include "ctkmain.h" |
| 42 | #include "ctkrecentmanager.h" |
| 43 | #include "ctkaccelmapprivate.h" |
| 44 | #include "ctkicontheme.h" |
| 45 | #include "ctkbuilder.h" |
| 46 | #include "ctkshortcutswindow.h" |
| 47 | #include "ctkintl.h" |
| 48 | |
| 49 | /* NB: please do not add backend-specific CDK headers here. This should |
| 50 | * be abstracted via CtkApplicationImpl. |
| 51 | */ |
| 52 | |
| 53 | /** |
| 54 | * SECTION:ctkapplication |
| 55 | * @title: CtkApplication |
| 56 | * @short_description: Application class |
| 57 | * |
| 58 | * #CtkApplication is a class that handles many important aspects |
| 59 | * of a CTK+ application in a convenient fashion, without enforcing |
| 60 | * a one-size-fits-all application model. |
| 61 | * |
| 62 | * Currently, CtkApplication handles CTK+ initialization, application |
| 63 | * uniqueness, session management, provides some basic scriptability and |
| 64 | * desktop shell integration by exporting actions and menus and manages a |
| 65 | * list of toplevel windows whose life-cycle is automatically tied to the |
| 66 | * life-cycle of your application. |
| 67 | * |
| 68 | * While CtkApplication works fine with plain #CtkWindows, it is recommended |
| 69 | * to use it together with #CtkApplicationWindow. |
| 70 | * |
| 71 | * When CDK threads are enabled, CtkApplication will acquire the CDK |
| 72 | * lock when invoking actions that arrive from other processes. The CDK |
| 73 | * lock is not touched for local action invocations. In order to have |
| 74 | * actions invoked in a predictable context it is therefore recommended |
| 75 | * that the CDK lock be held while invoking actions locally with |
| 76 | * g_action_group_activate_action(). The same applies to actions |
| 77 | * associated with #CtkApplicationWindow and to the “activate” and |
| 78 | * “open” #GApplication methods. |
| 79 | * |
| 80 | * ## Automatic resources ## {#automatic-resources} |
| 81 | * |
| 82 | * #CtkApplication will automatically load menus from the #CtkBuilder |
| 83 | * resource located at "ctk/menus.ui", relative to the application's |
| 84 | * resource base path (see g_application_set_resource_base_path()). The |
| 85 | * menu with the ID "app-menu" is taken as the application's app menu |
| 86 | * and the menu with the ID "menubar" is taken as the application's |
| 87 | * menubar. Additional menus (most interesting submenus) can be named |
| 88 | * and accessed via ctk_application_get_menu_by_id() which allows for |
| 89 | * dynamic population of a part of the menu structure. |
| 90 | * |
| 91 | * If the resources "ctk/menus-appmenu.ui" or "ctk/menus-traditional.ui" are |
| 92 | * present then these files will be used in preference, depending on the value |
| 93 | * of ctk_application_prefers_app_menu(). If the resource "ctk/menus-common.ui" |
| 94 | * is present it will be loaded as well. This is useful for storing items that |
| 95 | * are referenced from both "ctk/menus-appmenu.ui" and |
| 96 | * "ctk/menus-traditional.ui". |
| 97 | * |
| 98 | * It is also possible to provide the menus manually using |
| 99 | * ctk_application_set_app_menu() and ctk_application_set_menubar(). |
| 100 | * |
| 101 | * #CtkApplication will also automatically setup an icon search path for |
| 102 | * the default icon theme by appending "icons" to the resource base |
| 103 | * path. This allows your application to easily store its icons as |
| 104 | * resources. See ctk_icon_theme_add_resource_path() for more |
| 105 | * information. |
| 106 | * |
| 107 | * If there is a resource located at "ctk/help-overlay.ui" which |
| 108 | * defines a #CtkShortcutsWindow with ID "help_overlay" then CtkApplication |
| 109 | * associates an instance of this shortcuts window with each |
| 110 | * #CtkApplicationWindow and sets up keyboard accelerators (Control-F1 |
| 111 | * and Control-?) to open it. To create a menu item that displays the |
| 112 | * shortcuts window, associate the item with the action win.show-help-overlay. |
| 113 | * |
| 114 | * ## A simple application ## {#ctkapplication} |
| 115 | * |
| 116 | * [A simple example](https://git.gnome.org/browse/ctk+/tree/examples/bp/bloatpad.c) |
| 117 | * |
| 118 | * CtkApplication optionally registers with a session manager |
| 119 | * of the users session (if you set the #CtkApplication:register-session |
| 120 | * property) and offers various functionality related to the session |
| 121 | * life-cycle. |
| 122 | * |
| 123 | * An application can block various ways to end the session with |
| 124 | * the ctk_application_inhibit() function. Typical use cases for |
| 125 | * this kind of inhibiting are long-running, uninterruptible operations, |
| 126 | * such as burning a CD or performing a disk backup. The session |
| 127 | * manager may not honor the inhibitor, but it can be expected to |
| 128 | * inform the user about the negative consequences of ending the |
| 129 | * session while inhibitors are present. |
| 130 | * |
| 131 | * ## See Also ## {#seealso} |
| 132 | * [HowDoI: Using CtkApplication](https://wiki.gnome.org/HowDoI/CtkApplication), |
| 133 | * [Getting Started with CTK+: Basics](https://developer.gnome.org/ctk3/stable/ctk-getting-started.html#id-1.2.3.3) |
| 134 | */ |
| 135 | |
| 136 | enum { |
| 137 | WINDOW_ADDED, |
| 138 | WINDOW_REMOVED, |
| 139 | QUERY_END, |
| 140 | LAST_SIGNAL |
| 141 | }; |
| 142 | |
| 143 | static guint ctk_application_signals[LAST_SIGNAL]; |
| 144 | |
| 145 | enum { |
| 146 | PROP_ZERO, |
| 147 | PROP_REGISTER_SESSION, |
| 148 | PROP_SCREENSAVER_ACTIVE, |
| 149 | PROP_APP_MENU, |
| 150 | PROP_MENUBAR, |
| 151 | PROP_ACTIVE_WINDOW, |
| 152 | NUM_PROPERTIES |
| 153 | }; |
| 154 | |
| 155 | static GParamSpec *ctk_application_props[NUM_PROPERTIES]; |
| 156 | |
| 157 | struct _CtkApplicationPrivate |
| 158 | { |
| 159 | CtkApplicationImpl *impl; |
| 160 | CtkApplicationAccels *accels; |
| 161 | |
| 162 | GList *windows; |
| 163 | |
| 164 | GMenuModel *app_menu; |
| 165 | GMenuModel *menubar; |
| 166 | guint last_window_id; |
| 167 | |
| 168 | gboolean register_session; |
| 169 | gboolean screensaver_active; |
| 170 | CtkActionMuxer *muxer; |
| 171 | CtkBuilder *menus_builder; |
| 172 | gchar *help_overlay_path; |
| 173 | guint profiler_id; |
| 174 | }; |
| 175 | |
| 176 | G_DEFINE_TYPE_WITH_PRIVATE (CtkApplication, ctk_application, G_TYPE_APPLICATION)static void ctk_application_init (CtkApplication *self); static void ctk_application_class_init (CtkApplicationClass *klass) ; static GType ctk_application_get_type_once (void); static gpointer ctk_application_parent_class = ((void*)0); static gint CtkApplication_private_offset ; static void ctk_application_class_intern_init (gpointer klass ) { ctk_application_parent_class = g_type_class_peek_parent ( klass); if (CtkApplication_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkApplication_private_offset); ctk_application_class_init ((CtkApplicationClass*) klass); } __attribute__ ((__unused__ )) static inline gpointer ctk_application_get_instance_private (CtkApplication *self) { return (((gpointer) ((guint8*) (self ) + (glong) (CtkApplication_private_offset)))); } GType ctk_application_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); (void) ( 0 ? (gpointer) * (&static_g_define_type_id) : ((void*)0)) ; (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = ctk_application_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType ctk_application_get_type_once (void ) { GType g_define_type_id = g_type_register_static_simple (( g_application_get_type ()), g_intern_static_string ("CtkApplication" ), sizeof (CtkApplicationClass), (GClassInitFunc)(void (*)(void )) ctk_application_class_intern_init, sizeof (CtkApplication) , (GInstanceInitFunc)(void (*)(void)) ctk_application_init, ( GTypeFlags) 0); { {{ CtkApplication_private_offset = g_type_add_instance_private (g_define_type_id, sizeof (CtkApplicationPrivate)); };} } return g_define_type_id; } |
| 177 | |
| 178 | static gboolean |
| 179 | ctk_application_focus_in_event_cb (CtkWindow *window, |
| 180 | CdkEventFocus *event G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 181 | CtkApplication *application) |
| 182 | { |
| 183 | CtkApplicationPrivate *priv = application->priv; |
| 184 | GList *link; |
| 185 | |
| 186 | /* Keep the window list sorted by most-recently-focused. */ |
| 187 | link = g_list_find (priv->windows, window); |
| 188 | if (link != NULL((void*)0) && link != priv->windows) |
| 189 | { |
| 190 | priv->windows = g_list_remove_link (priv->windows, link); |
| 191 | priv->windows = g_list_concat (link, priv->windows); |
| 192 | } |
| 193 | |
| 194 | if (application->priv->impl) |
| 195 | ctk_application_impl_active_window_changed (application->priv->impl, window); |
| 196 | |
| 197 | g_object_notify_by_pspec (G_OBJECT (application)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), (((GType) ((20) << (2)))))))), ctk_application_props[PROP_ACTIVE_WINDOW]); |
| 198 | |
| 199 | return CDK_EVENT_PROPAGATE((0)); |
| 200 | } |
| 201 | |
| 202 | static void |
| 203 | ctk_application_load_resources (CtkApplication *application) |
| 204 | { |
| 205 | const gchar *base_path; |
| 206 | |
| 207 | base_path = g_application_get_resource_base_path (G_APPLICATION (application)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), ((g_application_get_type ()))))))); |
| 208 | |
| 209 | if (base_path == NULL((void*)0)) |
| 210 | return; |
| 211 | |
| 212 | /* Expand the icon search path */ |
| 213 | { |
| 214 | CtkIconTheme *default_theme; |
| 215 | gchar *iconspath; |
| 216 | |
| 217 | default_theme = ctk_icon_theme_get_default (); |
| 218 | iconspath = g_strconcat (base_path, "/icons/", NULL((void*)0)); |
| 219 | ctk_icon_theme_add_resource_path (default_theme, iconspath); |
| 220 | g_free (iconspath); |
| 221 | } |
| 222 | |
| 223 | /* Load the menus */ |
| 224 | { |
| 225 | gchar *menuspath; |
| 226 | |
| 227 | /* If the user has given a specific file for the variant of menu |
| 228 | * that we are looking for, use it with preference. |
| 229 | */ |
| 230 | if (ctk_application_prefers_app_menu (application)) |
| 231 | menuspath = g_strconcat (base_path, "/ctk/menus-appmenu.ui", NULL((void*)0)); |
| 232 | else |
| 233 | menuspath = g_strconcat (base_path, "/ctk/menus-traditional.ui", NULL((void*)0)); |
| 234 | |
| 235 | if (g_resources_get_info (menuspath, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL((void*)0), NULL((void*)0), NULL((void*)0))) |
| 236 | application->priv->menus_builder = ctk_builder_new_from_resource (menuspath); |
| 237 | g_free (menuspath); |
| 238 | |
| 239 | /* If we didn't get the specific file, fall back. */ |
| 240 | if (application->priv->menus_builder == NULL((void*)0)) |
| 241 | { |
| 242 | menuspath = g_strconcat (base_path, "/ctk/menus.ui", NULL((void*)0)); |
| 243 | if (g_resources_get_info (menuspath, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL((void*)0), NULL((void*)0), NULL((void*)0))) |
| 244 | application->priv->menus_builder = ctk_builder_new_from_resource (menuspath); |
| 245 | g_free (menuspath); |
| 246 | } |
| 247 | |
| 248 | /* Always load from -common as well, if we have it */ |
| 249 | menuspath = g_strconcat (base_path, "/ctk/menus-common.ui", NULL((void*)0)); |
| 250 | if (g_resources_get_info (menuspath, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL((void*)0), NULL((void*)0), NULL((void*)0))) |
| 251 | { |
| 252 | GError *error = NULL((void*)0); |
| 253 | |
| 254 | if (application->priv->menus_builder == NULL((void*)0)) |
| 255 | application->priv->menus_builder = ctk_builder_new (); |
| 256 | |
| 257 | if (!ctk_builder_add_from_resource (application->priv->menus_builder, menuspath, &error)) |
| 258 | g_error ("failed to load menus-common.ui: %s", error->message); |
| 259 | } |
| 260 | g_free (menuspath); |
| 261 | |
| 262 | if (application->priv->menus_builder) |
| 263 | { |
| 264 | GObject *menu; |
| 265 | |
| 266 | menu = ctk_builder_get_object (application->priv->menus_builder, "app-menu"); |
| 267 | if (menu != NULL((void*)0) && G_IS_MENU_MODEL (menu)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (menu)); GType __t = ((g_menu_model_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) |
| 268 | ctk_application_set_app_menu (application, G_MENU_MODEL (menu)((((GMenuModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((g_menu_model_get_type ()))))))); |
| 269 | menu = ctk_builder_get_object (application->priv->menus_builder, "menubar"); |
| 270 | if (menu != NULL((void*)0) && G_IS_MENU_MODEL (menu)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (menu)); GType __t = ((g_menu_model_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) |
| 271 | ctk_application_set_menubar (application, G_MENU_MODEL (menu)((((GMenuModel*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((menu)), ((g_menu_model_get_type ()))))))); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | /* Help overlay */ |
| 276 | { |
| 277 | gchar *path; |
| 278 | |
| 279 | path = g_strconcat (base_path, "/ctk/help-overlay.ui", NULL((void*)0)); |
| 280 | if (g_resources_get_info (path, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL((void*)0), NULL((void*)0), NULL((void*)0))) |
| 281 | { |
| 282 | const gchar * const accels[] = { "<Primary>F1", "<Primary>question", NULL((void*)0) }; |
| 283 | |
| 284 | application->priv->help_overlay_path = path; |
| 285 | ctk_application_set_accels_for_action (application, "win.show-help-overlay", accels); |
| 286 | } |
| 287 | else |
| 288 | { |
| 289 | g_free (path); |
| 290 | } |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | |
| 295 | static void |
| 296 | ctk_application_startup (GApplication *g_application) |
| 297 | { |
| 298 | CtkApplication *application = CTK_APPLICATION (g_application)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((g_application)), ((ctk_application_get_type ())))))); |
| 299 | |
| 300 | G_APPLICATION_CLASS (ctk_application_parent_class)((((GApplicationClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_application_parent_class)), ((g_application_get_type ()))))))->startup (g_application); |
| 301 | |
| 302 | ctk_action_muxer_insert (application->priv->muxer, "app", G_ACTION_GROUP (application)((((GActionGroup*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), ((g_action_group_get_type ()))))))); |
| 303 | |
| 304 | ctk_init (NULL((void*)0), NULL((void*)0)); |
| 305 | |
| 306 | application->priv->impl = ctk_application_impl_new (application, cdk_display_get_default ()); |
| 307 | ctk_application_impl_startup (application->priv->impl, application->priv->register_session); |
| 308 | |
| 309 | ctk_application_load_resources (application); |
| 310 | } |
| 311 | |
| 312 | static void |
| 313 | ctk_application_shutdown (GApplication *g_application) |
| 314 | { |
| 315 | CtkApplication *application = CTK_APPLICATION (g_application)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((g_application)), ((ctk_application_get_type ())))))); |
| 316 | |
| 317 | if (application->priv->impl == NULL((void*)0)) |
| 318 | return; |
| 319 | |
| 320 | ctk_application_impl_shutdown (application->priv->impl); |
| 321 | g_clear_object (&application->priv->impl)do { _Static_assert (sizeof *((&application->priv-> impl)) == sizeof (gpointer), "Expression evaluates to false") ; __typeof__ (((&application->priv->impl))) _pp = ( (&application->priv->impl)); __typeof__ (*((&application ->priv->impl))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr ) (g_object_unref) (_ptr); } while (0); |
| 322 | |
| 323 | ctk_action_muxer_remove (application->priv->muxer, "app"); |
| 324 | |
| 325 | /* Keep this section in sync with ctk_main() */ |
| 326 | |
| 327 | /* Try storing all clipboard data we have */ |
| 328 | _ctk_clipboard_store_all (); |
| 329 | |
| 330 | /* Synchronize the recent manager singleton */ |
| 331 | _ctk_recent_manager_sync (); |
| 332 | |
| 333 | G_APPLICATION_CLASS (ctk_application_parent_class)((((GApplicationClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_application_parent_class)), ((g_application_get_type ()))))))->shutdown (g_application); |
| 334 | } |
| 335 | |
| 336 | static gboolean |
| 337 | ctk_application_local_command_line (GApplication *application, |
| 338 | gchar ***arguments, |
| 339 | gint *exit_status) |
| 340 | { |
| 341 | g_application_add_option_group (application, ctk_get_option_group (FALSE(0))); |
| 342 | |
| 343 | return G_APPLICATION_CLASS (ctk_application_parent_class)((((GApplicationClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_application_parent_class)), ((g_application_get_type ()))))))->local_command_line (application, arguments, exit_status); |
| 344 | } |
| 345 | |
| 346 | static void |
| 347 | ctk_application_add_platform_data (GApplication *application G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 348 | GVariantBuilder *builder) |
| 349 | { |
| 350 | /* This is slightly evil. |
| 351 | * |
| 352 | * We don't have an impl here because we're remote so we can't figure |
| 353 | * out what to do on a per-display-server basis. |
| 354 | * |
| 355 | * So we do all the things... which currently is just one thing. |
| 356 | */ |
| 357 | const gchar *desktop_startup_id = |
| 358 | CDK_PRIVATE_CALL (cdk_get_desktop_startup_id)(cdk__private__ ()->cdk_get_desktop_startup_id) (); |
| 359 | if (desktop_startup_id) |
| 360 | g_variant_builder_add (builder, "{sv}", "desktop-startup-id", |
| 361 | g_variant_new_string (desktop_startup_id)); |
| 362 | } |
| 363 | |
| 364 | static void |
| 365 | ctk_application_before_emit (GApplication *g_application, |
| 366 | GVariant *platform_data) |
| 367 | { |
| 368 | CtkApplication *application = CTK_APPLICATION (g_application)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((g_application)), ((ctk_application_get_type ())))))); |
| 369 | |
| 370 | cdk_threads_enter (); |
| 371 | |
| 372 | ctk_application_impl_before_emit (application->priv->impl, platform_data); |
| 373 | } |
| 374 | |
| 375 | static void |
| 376 | ctk_application_after_emit (GApplication *application G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 377 | GVariant *platform_data) |
| 378 | { |
| 379 | const char *startup_notification_id = NULL((void*)0); |
| 380 | |
| 381 | g_variant_lookup (platform_data, "desktop-startup-id", "&s", &startup_notification_id); |
| 382 | if (startup_notification_id) |
| 383 | { |
| 384 | CdkDisplay *display; |
| 385 | |
| 386 | display = cdk_display_get_default (); |
| 387 | if (display) |
| 388 | cdk_display_notify_startup_complete (display, startup_notification_id); |
| 389 | } |
| 390 | |
| 391 | cdk_threads_leave (); |
| 392 | } |
| 393 | |
| 394 | static void |
| 395 | ctk_application_init (CtkApplication *application) |
| 396 | { |
| 397 | application->priv = ctk_application_get_instance_private (application); |
| 398 | |
| 399 | application->priv->muxer = ctk_action_muxer_new (); |
| 400 | |
| 401 | application->priv->accels = ctk_application_accels_new (); |
| 402 | |
| 403 | /* getenv now at the latest */ |
| 404 | CDK_PRIVATE_CALL (cdk_get_desktop_startup_id)(cdk__private__ ()->cdk_get_desktop_startup_id) (); |
| 405 | } |
| 406 | |
| 407 | static void |
| 408 | ctk_application_window_added (CtkApplication *application, |
| 409 | CtkWindow *window) |
| 410 | { |
| 411 | CtkApplicationPrivate *priv = application->priv; |
| 412 | |
| 413 | if (CTK_IS_APPLICATION_WINDOW (window)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (window)); GType __t = ((ctk_application_window_get_type ())) ; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } ))))) |
| 414 | { |
| 415 | ctk_application_window_set_id (CTK_APPLICATION_WINDOW (window)((((CtkApplicationWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), ((ctk_application_window_get_type ())))))), ++priv->last_window_id); |
| 416 | if (priv->help_overlay_path) |
| 417 | { |
| 418 | CtkBuilder *builder; |
| 419 | CtkWidget *help_overlay; |
| 420 | |
| 421 | builder = ctk_builder_new_from_resource (priv->help_overlay_path); |
| 422 | help_overlay = CTK_WIDGET (ctk_builder_get_object (builder, "help_overlay"))((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((ctk_builder_get_object (builder, "help_overlay"))), ((ctk_widget_get_type ())))))); |
| 423 | if (CTK_IS_SHORTCUTS_WINDOW (help_overlay)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (help_overlay)); GType __t = ((ctk_shortcuts_window_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) |
| 424 | ctk_application_window_set_help_overlay (CTK_APPLICATION_WINDOW (window)((((CtkApplicationWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), ((ctk_application_window_get_type ())))))), |
| 425 | CTK_SHORTCUTS_WINDOW (help_overlay)((((CtkShortcutsWindow*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((help_overlay)), ((ctk_shortcuts_window_get_type ()))))))); |
| 426 | g_object_unref (builder); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | priv->windows = g_list_prepend (priv->windows, window); |
| 431 | ctk_window_set_application (window, application); |
| 432 | g_application_hold (G_APPLICATION (application)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), ((g_application_get_type ()))))))); |
| 433 | |
| 434 | g_signal_connect (window, "focus-in-event",g_signal_connect_data ((window), ("focus-in-event"), (((GCallback ) (ctk_application_focus_in_event_cb))), (application), ((void *)0), (GConnectFlags) 0) |
| 435 | G_CALLBACK (ctk_application_focus_in_event_cb),g_signal_connect_data ((window), ("focus-in-event"), (((GCallback ) (ctk_application_focus_in_event_cb))), (application), ((void *)0), (GConnectFlags) 0) |
| 436 | application)g_signal_connect_data ((window), ("focus-in-event"), (((GCallback ) (ctk_application_focus_in_event_cb))), (application), ((void *)0), (GConnectFlags) 0); |
| 437 | |
| 438 | ctk_application_impl_window_added (priv->impl, window); |
| 439 | |
| 440 | ctk_application_impl_active_window_changed (priv->impl, window); |
| 441 | |
| 442 | g_object_notify_by_pspec (G_OBJECT (application)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), (((GType) ((20) << (2)))))))), ctk_application_props[PROP_ACTIVE_WINDOW]); |
| 443 | } |
| 444 | |
| 445 | static void |
| 446 | ctk_application_window_removed (CtkApplication *application, |
| 447 | CtkWindow *window) |
| 448 | { |
| 449 | CtkApplicationPrivate *priv = application->priv; |
| 450 | gpointer old_active; |
| 451 | |
| 452 | old_active = priv->windows; |
| 453 | |
| 454 | if (priv->impl) |
| 455 | ctk_application_impl_window_removed (priv->impl, window); |
| 456 | |
| 457 | g_signal_handlers_disconnect_by_func (window,g_signal_handlers_disconnect_matched ((window), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (ctk_application_focus_in_event_cb), (application)) |
| 458 | ctk_application_focus_in_event_cb,g_signal_handlers_disconnect_matched ((window), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (ctk_application_focus_in_event_cb), (application)) |
| 459 | application)g_signal_handlers_disconnect_matched ((window), (GSignalMatchType ) (G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA), 0, 0, ((void*) 0), (ctk_application_focus_in_event_cb), (application)); |
| 460 | |
| 461 | g_application_release (G_APPLICATION (application)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), ((g_application_get_type ()))))))); |
| 462 | priv->windows = g_list_remove (priv->windows, window); |
| 463 | ctk_window_set_application (window, NULL((void*)0)); |
| 464 | |
| 465 | if (priv->windows != old_active && priv->impl) |
| 466 | { |
| 467 | ctk_application_impl_active_window_changed (priv->impl, priv->windows ? priv->windows->data : NULL((void*)0)); |
| 468 | g_object_notify_by_pspec (G_OBJECT (application)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), (((GType) ((20) << (2)))))))), ctk_application_props[PROP_ACTIVE_WINDOW]); |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | static void |
| 473 | extract_accel_from_menu_item (GMenuModel *model, |
| 474 | gint item, |
| 475 | CtkApplication *app) |
| 476 | { |
| 477 | GMenuAttributeIter *iter; |
| 478 | const gchar *key; |
| 479 | GVariant *value; |
| 480 | const gchar *accel = NULL((void*)0); |
| 481 | const gchar *action = NULL((void*)0); |
| 482 | GVariant *target = NULL((void*)0); |
| 483 | |
| 484 | iter = g_menu_model_iterate_item_attributes (model, item); |
| 485 | while (g_menu_attribute_iter_get_next (iter, &key, &value)) |
| 486 | { |
| 487 | if (g_str_equal (key, "action")(strcmp ((const char *) (key), (const char *) ("action")) == 0 ) && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING((const GVariantType *) "s"))) |
Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption | |
| 488 | action = g_variant_get_string (value, NULL((void*)0)); |
| 489 | else if (g_str_equal (key, "accel")(strcmp ((const char *) (key), (const char *) ("accel")) == 0 ) && g_variant_is_of_type (value, G_VARIANT_TYPE_STRING((const GVariantType *) "s"))) |
| 490 | accel = g_variant_get_string (value, NULL((void*)0)); |
| 491 | else if (g_str_equal (key, "target")(strcmp ((const char *) (key), (const char *) ("target")) == 0 )) |
| 492 | target = g_variant_ref (value); |
| 493 | g_variant_unref (value); |
| 494 | } |
| 495 | g_object_unref (iter); |
| 496 | |
| 497 | if (accel && action) |
| 498 | { |
| 499 | const gchar *accels[2] = { accel, NULL((void*)0) }; |
| 500 | gchar *detailed_action_name; |
| 501 | |
| 502 | detailed_action_name = g_action_print_detailed_name (action, target); |
| 503 | ctk_application_set_accels_for_action (app, detailed_action_name, accels); |
| 504 | g_free (detailed_action_name); |
| 505 | } |
| 506 | |
| 507 | if (target) |
| 508 | g_variant_unref (target); |
| 509 | } |
| 510 | |
| 511 | static void |
| 512 | extract_accels_from_menu (GMenuModel *model, |
| 513 | CtkApplication *app) |
| 514 | { |
| 515 | gint i; |
| 516 | |
| 517 | for (i = 0; i < g_menu_model_get_n_items (model); i++) |
| 518 | { |
| 519 | GMenuLinkIter *iter; |
| 520 | GMenuModel *sub_model; |
| 521 | |
| 522 | extract_accel_from_menu_item (model, i, app); |
| 523 | |
| 524 | iter = g_menu_model_iterate_item_links (model, i); |
| 525 | while (g_menu_link_iter_get_next (iter, NULL((void*)0), &sub_model)) |
| 526 | { |
| 527 | extract_accels_from_menu (sub_model, app); |
| 528 | g_object_unref (sub_model); |
| 529 | } |
| 530 | g_object_unref (iter); |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | static void |
| 535 | ctk_application_get_property (GObject *object, |
| 536 | guint prop_id, |
| 537 | GValue *value, |
| 538 | GParamSpec *pspec) |
| 539 | { |
| 540 | CtkApplication *application = CTK_APPLICATION (object)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_application_get_type ())))))); |
| 541 | |
| 542 | switch (prop_id) |
| 543 | { |
| 544 | case PROP_REGISTER_SESSION: |
| 545 | g_value_set_boolean (value, application->priv->register_session); |
| 546 | break; |
| 547 | |
| 548 | case PROP_SCREENSAVER_ACTIVE: |
| 549 | g_value_set_boolean (value, application->priv->screensaver_active); |
| 550 | break; |
| 551 | |
| 552 | case PROP_APP_MENU: |
| 553 | g_value_set_object (value, ctk_application_get_app_menu (application)); |
| 554 | break; |
| 555 | |
| 556 | case PROP_MENUBAR: |
| 557 | g_value_set_object (value, ctk_application_get_menubar (application)); |
| 558 | break; |
| 559 | |
| 560 | case PROP_ACTIVE_WINDOW: |
| 561 | g_value_set_object (value, ctk_application_get_active_window (application)); |
| 562 | break; |
| 563 | |
| 564 | default: |
| 565 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "ctkapplication.c", 565, ("property"), _glib__property_id, _glib__pspec ->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) ( _glib__pspec))->g_class))->g_type)))), (g_type_name ((( (((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); |
| 566 | break; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | static void |
| 571 | ctk_application_set_property (GObject *object, |
| 572 | guint prop_id, |
| 573 | const GValue *value, |
| 574 | GParamSpec *pspec) |
| 575 | { |
| 576 | CtkApplication *application = CTK_APPLICATION (object)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_application_get_type ())))))); |
| 577 | |
| 578 | switch (prop_id) |
| 579 | { |
| 580 | case PROP_REGISTER_SESSION: |
| 581 | application->priv->register_session = g_value_get_boolean (value); |
| 582 | break; |
| 583 | |
| 584 | case PROP_APP_MENU: |
| 585 | ctk_application_set_app_menu (application, g_value_get_object (value)); |
| 586 | break; |
| 587 | |
| 588 | case PROP_MENUBAR: |
| 589 | ctk_application_set_menubar (application, g_value_get_object (value)); |
| 590 | break; |
| 591 | |
| 592 | default: |
| 593 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "ctkapplication.c", 593, ("property"), _glib__property_id, _glib__pspec ->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) ( _glib__pspec))->g_class))->g_type)))), (g_type_name ((( (((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); |
| 594 | break; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | static void |
| 599 | ctk_application_finalize (GObject *object) |
| 600 | { |
| 601 | CtkApplication *application = CTK_APPLICATION (object)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_application_get_type ())))))); |
| 602 | |
| 603 | g_clear_object (&application->priv->menus_builder)do { _Static_assert (sizeof *((&application->priv-> menus_builder)) == sizeof (gpointer), "Expression evaluates to false" ); __typeof__ (((&application->priv->menus_builder) )) _pp = ((&application->priv->menus_builder)); __typeof__ (*((&application->priv->menus_builder))) _ptr = *_pp ; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); |
| 604 | g_clear_object (&application->priv->app_menu)do { _Static_assert (sizeof *((&application->priv-> app_menu)) == sizeof (gpointer), "Expression evaluates to false" ); __typeof__ (((&application->priv->app_menu))) _pp = ((&application->priv->app_menu)); __typeof__ (*( (&application->priv->app_menu))) _ptr = *_pp; *_pp = ((void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); |
| 605 | g_clear_object (&application->priv->menubar)do { _Static_assert (sizeof *((&application->priv-> menubar)) == sizeof (gpointer), "Expression evaluates to false" ); __typeof__ (((&application->priv->menubar))) _pp = ((&application->priv->menubar)); __typeof__ (*(( &application->priv->menubar))) _ptr = *_pp; *_pp = ( (void*)0); if (_ptr) (g_object_unref) (_ptr); } while (0); |
| 606 | g_clear_object (&application->priv->muxer)do { _Static_assert (sizeof *((&application->priv-> muxer)) == sizeof (gpointer), "Expression evaluates to false" ); __typeof__ (((&application->priv->muxer))) _pp = ((&application->priv->muxer)); __typeof__ (*((& application->priv->muxer))) _ptr = *_pp; *_pp = ((void* )0); if (_ptr) (g_object_unref) (_ptr); } while (0); |
| 607 | g_clear_object (&application->priv->accels)do { _Static_assert (sizeof *((&application->priv-> accels)) == sizeof (gpointer), "Expression evaluates to false" ); __typeof__ (((&application->priv->accels))) _pp = ((&application->priv->accels)); __typeof__ (*((& application->priv->accels))) _ptr = *_pp; *_pp = ((void *)0); if (_ptr) (g_object_unref) (_ptr); } while (0); |
| 608 | |
| 609 | g_free (application->priv->help_overlay_path); |
| 610 | |
| 611 | G_OBJECT_CLASS (ctk_application_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_application_parent_class)), (((GType) ((20) << (2))))))))->finalize (object); |
| 612 | } |
| 613 | |
| 614 | #ifdef G_OS_UNIX |
| 615 | |
| 616 | static const gchar org_gnome_Sysprof3_Profiler_xml[] = |
| 617 | "<node>" |
| 618 | "<interface name='org.gnome.Sysprof3.Profiler'>" |
| 619 | "<property name='Capabilities' type='a{sv}' access='read'/>" |
| 620 | "<method name='Start'>" |
| 621 | "<arg type='a{sv}' name='options' direction='in'/>" |
| 622 | "<arg type='h' name='fd' direction='in'/>" |
| 623 | "</method>" |
| 624 | "<method name='Stop'>" |
| 625 | "</method>" |
| 626 | "</interface>" |
| 627 | "</node>"; |
| 628 | |
| 629 | static GDBusInterfaceInfo *org_gnome_Sysprof3_Profiler; |
| 630 | |
| 631 | static void |
| 632 | sysprof_profiler_method_call (GDBusConnection *connection G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 633 | const gchar *sender G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 634 | const gchar *object_path G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 635 | const gchar *interface_name G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 636 | const gchar *method_name, |
| 637 | GVariant *parameters, |
| 638 | GDBusMethodInvocation *invocation, |
| 639 | gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__))) |
| 640 | { |
| 641 | if (strcmp (method_name, "Start") == 0) |
| 642 | { |
| 643 | GDBusMessage *message; |
| 644 | GUnixFDList *fd_list; |
| 645 | GVariant *options; |
| 646 | int fd = -1; |
| 647 | int idx; |
| 648 | |
| 649 | if (CDK_PRIVATE_CALL (cdk_profiler_is_running)(cdk__private__ ()->cdk_profiler_is_running) ()) |
| 650 | { |
| 651 | g_dbus_method_invocation_return_error (invocation, |
| 652 | G_DBUS_ERRORg_dbus_error_quark(), |
| 653 | G_DBUS_ERROR_FAILED, |
| 654 | "Profiler already running"); |
| 655 | return; |
| 656 | } |
| 657 | |
| 658 | g_variant_get (parameters, "(@a{sv}h)", &options, &idx); |
| 659 | |
| 660 | message = g_dbus_method_invocation_get_message (invocation); |
| 661 | fd_list = g_dbus_message_get_unix_fd_list (message); |
| 662 | if (fd_list) |
| 663 | fd = g_unix_fd_list_get (fd_list, idx, NULL((void*)0)); |
| 664 | |
| 665 | CDK_PRIVATE_CALL (cdk_profiler_start)(cdk__private__ ()->cdk_profiler_start) (fd); |
| 666 | |
| 667 | g_variant_unref (options); |
| 668 | } |
| 669 | else if (strcmp (method_name, "Stop") == 0) |
| 670 | { |
| 671 | if (!CDK_PRIVATE_CALL (cdk_profiler_is_running)(cdk__private__ ()->cdk_profiler_is_running) ()) |
| 672 | { |
| 673 | g_dbus_method_invocation_return_error (invocation, |
| 674 | G_DBUS_ERRORg_dbus_error_quark(), |
| 675 | G_DBUS_ERROR_FAILED, |
| 676 | "Profiler not running"); |
| 677 | return; |
| 678 | } |
| 679 | |
| 680 | CDK_PRIVATE_CALL (cdk_profiler_stop)(cdk__private__ ()->cdk_profiler_stop) (); |
| 681 | } |
| 682 | else |
| 683 | { |
| 684 | g_dbus_method_invocation_return_error (invocation, |
| 685 | G_DBUS_ERRORg_dbus_error_quark(), |
| 686 | G_DBUS_ERROR_UNKNOWN_METHOD, |
| 687 | "Unknown method"); |
| 688 | return; |
| 689 | } |
| 690 | |
| 691 | g_dbus_method_invocation_return_value (invocation, NULL((void*)0)); |
| 692 | } |
| 693 | |
| 694 | static gboolean |
| 695 | ctk_application_dbus_register (GApplication *application, |
| 696 | GDBusConnection *connection, |
| 697 | const char *obect_path G_GNUC_UNUSED__attribute__ ((__unused__)), |
| 698 | GError **error) |
| 699 | { |
| 700 | CtkApplicationPrivate *priv = ctk_application_get_instance_private (CTK_APPLICATION (application)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), ((ctk_application_get_type ()))))))); |
| 701 | GDBusInterfaceVTable vtable = { |
| 702 | .method_call = sysprof_profiler_method_call |
| 703 | }; |
| 704 | |
| 705 | if (org_gnome_Sysprof3_Profiler == NULL((void*)0)) |
| 706 | { |
| 707 | GDBusNodeInfo *info; |
| 708 | |
| 709 | info = g_dbus_node_info_new_for_xml (org_gnome_Sysprof3_Profiler_xml, error); |
| 710 | if (info == NULL((void*)0)) |
| 711 | return FALSE(0); |
| 712 | |
| 713 | org_gnome_Sysprof3_Profiler = g_dbus_node_info_lookup_interface (info, "org.gnome.Sysprof3.Profiler"); |
| 714 | g_dbus_interface_info_ref (org_gnome_Sysprof3_Profiler); |
| 715 | g_dbus_node_info_unref (info); |
| 716 | } |
| 717 | |
| 718 | priv->profiler_id = g_dbus_connection_register_object (connection, |
| 719 | "/org/ctk/Profiler", |
| 720 | org_gnome_Sysprof3_Profiler, |
| 721 | &vtable, |
| 722 | NULL((void*)0), |
| 723 | NULL((void*)0), |
| 724 | error); |
| 725 | |
| 726 | return TRUE(!(0)); |
| 727 | } |
| 728 | |
| 729 | static void |
| 730 | ctk_application_dbus_unregister (GApplication *application, |
| 731 | GDBusConnection *connection, |
| 732 | const char *obect_path G_GNUC_UNUSED__attribute__ ((__unused__))) |
| 733 | { |
| 734 | CtkApplicationPrivate *priv = ctk_application_get_instance_private (CTK_APPLICATION (application)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), ((ctk_application_get_type ()))))))); |
| 735 | |
| 736 | g_dbus_connection_unregister_object (connection, priv->profiler_id); |
| 737 | } |
| 738 | |
| 739 | #else |
| 740 | |
| 741 | static gboolean |
| 742 | ctk_application_dbus_register (GApplication *application, |
| 743 | GDBusConnection *connection, |
| 744 | const char *obect_path, |
| 745 | GError **error) |
| 746 | { |
| 747 | return TRUE(!(0)); |
| 748 | } |
| 749 | |
| 750 | static void |
| 751 | ctk_application_dbus_unregister (GApplication *application, |
| 752 | GDBusConnection *connection, |
| 753 | const char *obect_path) |
| 754 | { |
| 755 | } |
| 756 | |
| 757 | #endif |
| 758 | |
| 759 | static void |
| 760 | ctk_application_class_init (CtkApplicationClass *class) |
| 761 | { |
| 762 | GObjectClass *object_class = G_OBJECT_CLASS (class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((class)), (((GType) ((20) << (2)))))))); |
| 763 | GApplicationClass *application_class = G_APPLICATION_CLASS (class)((((GApplicationClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((class)), ((g_application_get_type ())))))); |
| 764 | |
| 765 | object_class->get_property = ctk_application_get_property; |
| 766 | object_class->set_property = ctk_application_set_property; |
| 767 | object_class->finalize = ctk_application_finalize; |
| 768 | |
| 769 | application_class->local_command_line = ctk_application_local_command_line; |
| 770 | application_class->add_platform_data = ctk_application_add_platform_data; |
| 771 | application_class->before_emit = ctk_application_before_emit; |
| 772 | application_class->after_emit = ctk_application_after_emit; |
| 773 | application_class->startup = ctk_application_startup; |
| 774 | application_class->shutdown = ctk_application_shutdown; |
| 775 | application_class->dbus_register = ctk_application_dbus_register; |
| 776 | application_class->dbus_unregister = ctk_application_dbus_unregister; |
| 777 | |
| 778 | class->window_added = ctk_application_window_added; |
| 779 | class->window_removed = ctk_application_window_removed; |
| 780 | |
| 781 | /** |
| 782 | * CtkApplication::window-added: |
| 783 | * @application: the #CtkApplication which emitted the signal |
| 784 | * @window: the newly-added #CtkWindow |
| 785 | * |
| 786 | * Emitted when a #CtkWindow is added to @application through |
| 787 | * ctk_application_add_window(). |
| 788 | * |
| 789 | * Since: 3.2 |
| 790 | */ |
| 791 | ctk_application_signals[WINDOW_ADDED] = |
| 792 | g_signal_new (I_("window-added")g_intern_static_string ("window-added"), CTK_TYPE_APPLICATION(ctk_application_get_type ()), G_SIGNAL_RUN_FIRST, |
| 793 | G_STRUCT_OFFSET (CtkApplicationClass, window_added)((glong) __builtin_offsetof(CtkApplicationClass, window_added )), |
| 794 | NULL((void*)0), NULL((void*)0), |
| 795 | NULL((void*)0), |
| 796 | G_TYPE_NONE((GType) ((1) << (2))), 1, CTK_TYPE_WINDOW(ctk_window_get_type ())); |
| 797 | |
| 798 | /** |
| 799 | * CtkApplication::window-removed: |
| 800 | * @application: the #CtkApplication which emitted the signal |
| 801 | * @window: the #CtkWindow that is being removed |
| 802 | * |
| 803 | * Emitted when a #CtkWindow is removed from @application, |
| 804 | * either as a side-effect of being destroyed or explicitly |
| 805 | * through ctk_application_remove_window(). |
| 806 | * |
| 807 | * Since: 3.2 |
| 808 | */ |
| 809 | ctk_application_signals[WINDOW_REMOVED] = |
| 810 | g_signal_new (I_("window-removed")g_intern_static_string ("window-removed"), CTK_TYPE_APPLICATION(ctk_application_get_type ()), G_SIGNAL_RUN_FIRST, |
| 811 | G_STRUCT_OFFSET (CtkApplicationClass, window_removed)((glong) __builtin_offsetof(CtkApplicationClass, window_removed )), |
| 812 | NULL((void*)0), NULL((void*)0), |
| 813 | NULL((void*)0), |
| 814 | G_TYPE_NONE((GType) ((1) << (2))), 1, CTK_TYPE_WINDOW(ctk_window_get_type ())); |
| 815 | |
| 816 | /** |
| 817 | * CtkApplication::query-end: |
| 818 | * @application: the #CtkApplication which emitted the signal |
| 819 | * |
| 820 | * Emitted when the session manager is about to end the session, only |
| 821 | * if #CtkApplication::register-session is %TRUE. Applications can |
| 822 | * connect to this signal and call ctk_application_inhibit() with |
| 823 | * %CTK_APPLICATION_INHIBIT_LOGOUT to delay the end of the session |
| 824 | * until state has been saved. |
| 825 | * |
| 826 | * Since: 3.24.8 |
| 827 | */ |
| 828 | ctk_application_signals[QUERY_END] = |
| 829 | g_signal_new (I_("query-end")g_intern_static_string ("query-end"), CTK_TYPE_APPLICATION(ctk_application_get_type ()), G_SIGNAL_RUN_FIRST, |
| 830 | 0, |
| 831 | NULL((void*)0), NULL((void*)0), |
| 832 | NULL((void*)0), |
| 833 | G_TYPE_NONE((GType) ((1) << (2))), 0); |
| 834 | /** |
| 835 | * CtkApplication:register-session: |
| 836 | * |
| 837 | * Set this property to %TRUE to register with the session manager. |
| 838 | * |
| 839 | * Since: 3.4 |
| 840 | */ |
| 841 | ctk_application_props[PROP_REGISTER_SESSION] = |
| 842 | g_param_spec_boolean ("register-session", |
| 843 | P_("Register session")g_dgettext("ctk30" "-properties","Register session"), |
| 844 | P_("Register with the session manager")g_dgettext("ctk30" "-properties","Register with the session manager" ), |
| 845 | FALSE(0), |
| 846 | G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS(G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB )); |
| 847 | |
| 848 | /** |
| 849 | * CtkApplication:screensaver-active: |
| 850 | * |
| 851 | * This property is %TRUE if CTK+ believes that the screensaver is |
| 852 | * currently active. CTK+ only tracks session state (including this) |
| 853 | * when #CtkApplication::register-session is set to %TRUE. |
| 854 | * |
| 855 | * Tracking the screensaver state is supported on Linux. |
| 856 | * |
| 857 | * Since: 3.24 |
| 858 | */ |
| 859 | ctk_application_props[PROP_SCREENSAVER_ACTIVE] = |
| 860 | g_param_spec_boolean ("screensaver-active", |
| 861 | P_("Screensaver Active")g_dgettext("ctk30" "-properties","Screensaver Active"), |
| 862 | P_("Whether the screensaver is active")g_dgettext("ctk30" "-properties","Whether the screensaver is active" ), |
| 863 | FALSE(0), |
| 864 | G_PARAM_READABLE|G_PARAM_STATIC_STRINGS(G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB )); |
| 865 | |
| 866 | ctk_application_props[PROP_APP_MENU] = |
| 867 | g_param_spec_object ("app-menu", |
| 868 | P_("Application menu")g_dgettext("ctk30" "-properties","Application menu"), |
| 869 | P_("The GMenuModel for the application menu")g_dgettext("ctk30" "-properties","The GMenuModel for the application menu" ), |
| 870 | G_TYPE_MENU_MODEL(g_menu_model_get_type ()), |
| 871 | G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS(G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB )); |
| 872 | |
| 873 | ctk_application_props[PROP_MENUBAR] = |
| 874 | g_param_spec_object ("menubar", |
| 875 | P_("Menubar")g_dgettext("ctk30" "-properties","Menubar"), |
| 876 | P_("The GMenuModel for the menubar")g_dgettext("ctk30" "-properties","The GMenuModel for the menubar" ), |
| 877 | G_TYPE_MENU_MODEL(g_menu_model_get_type ()), |
| 878 | G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS(G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB )); |
| 879 | |
| 880 | ctk_application_props[PROP_ACTIVE_WINDOW] = |
| 881 | g_param_spec_object ("active-window", |
| 882 | P_("Active window")g_dgettext("ctk30" "-properties","Active window"), |
| 883 | P_("The window which most recently had focus")g_dgettext("ctk30" "-properties","The window which most recently had focus" ), |
| 884 | CTK_TYPE_WINDOW(ctk_window_get_type ()), |
| 885 | G_PARAM_READABLE|G_PARAM_STATIC_STRINGS(G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB )); |
| 886 | |
| 887 | g_object_class_install_properties (object_class, NUM_PROPERTIES, ctk_application_props); |
| 888 | } |
| 889 | |
| 890 | /** |
| 891 | * ctk_application_new: |
| 892 | * @application_id: (allow-none): The application ID. |
| 893 | * @flags: the application flags |
| 894 | * |
| 895 | * Creates a new #CtkApplication instance. |
| 896 | * |
| 897 | * When using #CtkApplication, it is not necessary to call ctk_init() |
| 898 | * manually. It is called as soon as the application gets registered as |
| 899 | * the primary instance. |
| 900 | * |
| 901 | * Concretely, ctk_init() is called in the default handler for the |
| 902 | * #GApplication::startup signal. Therefore, #CtkApplication subclasses should |
| 903 | * chain up in their #GApplication::startup handler before using any CTK+ API. |
| 904 | * |
| 905 | * Note that commandline arguments are not passed to ctk_init(). |
| 906 | * All CTK+ functionality that is available via commandline arguments |
| 907 | * can also be achieved by setting suitable environment variables |
| 908 | * such as `G_DEBUG`, so this should not be a big |
| 909 | * problem. If you absolutely must support CTK+ commandline arguments, |
| 910 | * you can explicitly call ctk_init() before creating the application |
| 911 | * instance. |
| 912 | * |
| 913 | * If non-%NULL, the application ID must be valid. See |
| 914 | * g_application_id_is_valid(). |
| 915 | * |
| 916 | * If no application ID is given then some features (most notably application |
| 917 | * uniqueness) will be disabled. A null application ID is only allowed with |
| 918 | * CTK+ 3.6 or later. |
| 919 | * |
| 920 | * Returns: a new #CtkApplication instance |
| 921 | * |
| 922 | * Since: 3.0 |
| 923 | */ |
| 924 | CtkApplication * |
| 925 | ctk_application_new (const gchar *application_id, |
| 926 | GApplicationFlags flags) |
| 927 | { |
| 928 | g_return_val_if_fail (application_id == NULL || g_application_id_is_valid (application_id), NULL)do { if ((application_id == ((void*)0) || g_application_id_is_valid (application_id))) { } else { g_return_if_fail_warning ("Ctk" , ((const char*) (__func__)), "application_id == NULL || g_application_id_is_valid (application_id)" ); return (((void*)0)); } } while (0); |
| 929 | |
| 930 | return g_object_new (CTK_TYPE_APPLICATION(ctk_application_get_type ()), |
| 931 | "application-id", application_id, |
| 932 | "flags", flags, |
| 933 | NULL((void*)0)); |
| 934 | } |
| 935 | |
| 936 | /** |
| 937 | * ctk_application_add_window: |
| 938 | * @application: a #CtkApplication |
| 939 | * @window: a #CtkWindow |
| 940 | * |
| 941 | * Adds a window to @application. |
| 942 | * |
| 943 | * This call can only happen after the @application has started; |
| 944 | * typically, you should add new application windows in response |
| 945 | * to the emission of the #GApplication::activate signal. |
| 946 | * |
| 947 | * This call is equivalent to setting the #CtkWindow:application |
| 948 | * property of @window to @application. |
| 949 | * |
| 950 | * Normally, the connection between the application and the window |
| 951 | * will remain until the window is destroyed, but you can explicitly |
| 952 | * remove it with ctk_application_remove_window(). |
| 953 | * |
| 954 | * CTK+ will keep the @application running as long as it has |
| 955 | * any windows. |
| 956 | * |
| 957 | * Since: 3.0 |
| 958 | **/ |
| 959 | void |
| 960 | ctk_application_add_window (CtkApplication *application, |
| 961 | CtkWindow *window) |
| 962 | { |
| 963 | g_return_if_fail (CTK_IS_APPLICATION (application))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return ; } } while (0); |
| 964 | g_return_if_fail (CTK_IS_WINDOW (window))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((window)); GType __t = ((ctk_window_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_WINDOW (window)"); return; } } while (0); |
| 965 | |
| 966 | if (!g_application_get_is_registered (G_APPLICATION (application)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), ((g_application_get_type ())))))))) |
| 967 | { |
| 968 | g_critical ("New application windows must be added after the " |
| 969 | "GApplication::startup signal has been emitted."); |
| 970 | return; |
| 971 | } |
| 972 | |
| 973 | if (!g_list_find (application->priv->windows, window)) |
| 974 | g_signal_emit (application, |
| 975 | ctk_application_signals[WINDOW_ADDED], 0, window); |
| 976 | } |
| 977 | |
| 978 | /** |
| 979 | * ctk_application_remove_window: |
| 980 | * @application: a #CtkApplication |
| 981 | * @window: a #CtkWindow |
| 982 | * |
| 983 | * Remove a window from @application. |
| 984 | * |
| 985 | * If @window belongs to @application then this call is equivalent to |
| 986 | * setting the #CtkWindow:application property of @window to |
| 987 | * %NULL. |
| 988 | * |
| 989 | * The application may stop running as a result of a call to this |
| 990 | * function. |
| 991 | * |
| 992 | * Since: 3.0 |
| 993 | **/ |
| 994 | void |
| 995 | ctk_application_remove_window (CtkApplication *application, |
| 996 | CtkWindow *window) |
| 997 | { |
| 998 | g_return_if_fail (CTK_IS_APPLICATION (application))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return ; } } while (0); |
| 999 | g_return_if_fail (CTK_IS_WINDOW (window))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((window)); GType __t = ((ctk_window_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__ )), "CTK_IS_WINDOW (window)"); return; } } while (0); |
| 1000 | |
| 1001 | if (g_list_find (application->priv->windows, window)) |
| 1002 | g_signal_emit (application, |
| 1003 | ctk_application_signals[WINDOW_REMOVED], 0, window); |
| 1004 | } |
| 1005 | |
| 1006 | /** |
| 1007 | * ctk_application_get_windows: |
| 1008 | * @application: a #CtkApplication |
| 1009 | * |
| 1010 | * Gets a list of the #CtkWindows associated with @application. |
| 1011 | * |
| 1012 | * The list is sorted by most recently focused window, such that the first |
| 1013 | * element is the currently focused window. (Useful for choosing a parent |
| 1014 | * for a transient window.) |
| 1015 | * |
| 1016 | * The list that is returned should not be modified in any way. It will |
| 1017 | * only remain valid until the next focus change or window creation or |
| 1018 | * deletion. |
| 1019 | * |
| 1020 | * Returns: (element-type CtkWindow) (transfer none): a #GList of #CtkWindow |
| 1021 | * |
| 1022 | * Since: 3.0 |
| 1023 | **/ |
| 1024 | GList * |
| 1025 | ctk_application_get_windows (CtkApplication *application) |
| 1026 | { |
| 1027 | g_return_val_if_fail (CTK_IS_APPLICATION (application), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return (((void*)0)); } } while (0); |
| 1028 | |
| 1029 | return application->priv->windows; |
| 1030 | } |
| 1031 | |
| 1032 | /** |
| 1033 | * ctk_application_get_window_by_id: |
| 1034 | * @application: a #CtkApplication |
| 1035 | * @id: an identifier number |
| 1036 | * |
| 1037 | * Returns the #CtkApplicationWindow with the given ID. |
| 1038 | * |
| 1039 | * The ID of a #CtkApplicationWindow can be retrieved with |
| 1040 | * ctk_application_window_get_id(). |
| 1041 | * |
| 1042 | * Returns: (nullable) (transfer none): the window with ID @id, or |
| 1043 | * %NULL if there is no window with this ID |
| 1044 | * |
| 1045 | * Since: 3.6 |
| 1046 | */ |
| 1047 | CtkWindow * |
| 1048 | ctk_application_get_window_by_id (CtkApplication *application, |
| 1049 | guint id) |
| 1050 | { |
| 1051 | GList *l; |
| 1052 | |
| 1053 | g_return_val_if_fail (CTK_IS_APPLICATION (application), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return (((void*)0)); } } while (0); |
| 1054 | |
| 1055 | for (l = application->priv->windows; l != NULL((void*)0); l = l->next) |
| 1056 | { |
| 1057 | if (CTK_IS_APPLICATION_WINDOW (l->data)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (l->data)); GType __t = ((ctk_application_window_get_type ( ))); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))) && |
| 1058 | ctk_application_window_get_id (CTK_APPLICATION_WINDOW (l->data)((((CtkApplicationWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((l->data)), ((ctk_application_window_get_type ()))))))) == id) |
| 1059 | return l->data; |
| 1060 | } |
| 1061 | |
| 1062 | return NULL((void*)0); |
| 1063 | } |
| 1064 | |
| 1065 | /** |
| 1066 | * ctk_application_get_active_window: |
| 1067 | * @application: a #CtkApplication |
| 1068 | * |
| 1069 | * Gets the “active” window for the application. |
| 1070 | * |
| 1071 | * The active window is the one that was most recently focused (within |
| 1072 | * the application). This window may not have the focus at the moment |
| 1073 | * if another application has it — this is just the most |
| 1074 | * recently-focused window within this application. |
| 1075 | * |
| 1076 | * Returns: (transfer none) (nullable): the active window, or %NULL if |
| 1077 | * there isn't one. |
| 1078 | * |
| 1079 | * Since: 3.6 |
| 1080 | **/ |
| 1081 | CtkWindow * |
| 1082 | ctk_application_get_active_window (CtkApplication *application) |
| 1083 | { |
| 1084 | g_return_val_if_fail (CTK_IS_APPLICATION (application), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return (((void*)0)); } } while (0); |
| 1085 | |
| 1086 | return application->priv->windows ? application->priv->windows->data : NULL((void*)0); |
| 1087 | } |
| 1088 | |
| 1089 | static void |
| 1090 | ctk_application_update_accels (CtkApplication *application) |
| 1091 | { |
| 1092 | GList *l; |
| 1093 | |
| 1094 | for (l = application->priv->windows; l != NULL((void*)0); l = l->next) |
| 1095 | _ctk_window_notify_keys_changed (l->data); |
| 1096 | } |
| 1097 | |
| 1098 | /** |
| 1099 | * ctk_application_add_accelerator: |
| 1100 | * @application: a #CtkApplication |
| 1101 | * @accelerator: accelerator string |
| 1102 | * @action_name: the name of the action to activate |
| 1103 | * @parameter: (allow-none): parameter to pass when activating the action, |
| 1104 | * or %NULL if the action does not accept an activation parameter |
| 1105 | * |
| 1106 | * Installs an accelerator that will cause the named action |
| 1107 | * to be activated when the key combination specificed by @accelerator |
| 1108 | * is pressed. |
| 1109 | * |
| 1110 | * @accelerator must be a string that can be parsed by ctk_accelerator_parse(), |
| 1111 | * e.g. "<Primary>q" or “<Control><Alt>p”. |
| 1112 | * |
| 1113 | * @action_name must be the name of an action as it would be used |
| 1114 | * in the app menu, i.e. actions that have been added to the application |
| 1115 | * are referred to with an “app.” prefix, and window-specific actions |
| 1116 | * with a “win.” prefix. |
| 1117 | * |
| 1118 | * CtkApplication also extracts accelerators out of “accel” attributes |
| 1119 | * in the #GMenuModels passed to ctk_application_set_app_menu() and |
| 1120 | * ctk_application_set_menubar(), which is usually more convenient |
| 1121 | * than calling this function for each accelerator. |
| 1122 | * |
| 1123 | * Since: 3.4 |
| 1124 | * |
| 1125 | * Deprecated: 3.14: Use ctk_application_set_accels_for_action() instead |
| 1126 | */ |
| 1127 | void |
| 1128 | ctk_application_add_accelerator (CtkApplication *application, |
| 1129 | const gchar *accelerator, |
| 1130 | const gchar *action_name, |
| 1131 | GVariant *parameter) |
| 1132 | { |
| 1133 | const gchar *accelerators[2] = { accelerator, NULL((void*)0) }; |
| 1134 | gchar *detailed_action_name; |
| 1135 | |
| 1136 | g_return_if_fail (CTK_IS_APPLICATION (application))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return ; } } while (0); |
| 1137 | g_return_if_fail (accelerator != NULL)do { if ((accelerator != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "accelerator != NULL"); return ; } } while (0); |
| 1138 | g_return_if_fail (action_name != NULL)do { if ((action_name != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "action_name != NULL"); return ; } } while (0); |
| 1139 | |
| 1140 | detailed_action_name = g_action_print_detailed_name (action_name, parameter); |
| 1141 | ctk_application_set_accels_for_action (application, detailed_action_name, accelerators); |
| 1142 | g_free (detailed_action_name); |
| 1143 | } |
| 1144 | |
| 1145 | /** |
| 1146 | * ctk_application_remove_accelerator: |
| 1147 | * @application: a #CtkApplication |
| 1148 | * @action_name: the name of the action to activate |
| 1149 | * @parameter: (allow-none): parameter to pass when activating the action, |
| 1150 | * or %NULL if the action does not accept an activation parameter |
| 1151 | * |
| 1152 | * Removes an accelerator that has been previously added |
| 1153 | * with ctk_application_add_accelerator(). |
| 1154 | * |
| 1155 | * Since: 3.4 |
| 1156 | * |
| 1157 | * Deprecated: 3.14: Use ctk_application_set_accels_for_action() instead |
| 1158 | */ |
| 1159 | void |
| 1160 | ctk_application_remove_accelerator (CtkApplication *application, |
| 1161 | const gchar *action_name, |
| 1162 | GVariant *parameter) |
| 1163 | { |
| 1164 | const gchar *accelerators[1] = { NULL((void*)0) }; |
| 1165 | gchar *detailed_action_name; |
| 1166 | |
| 1167 | g_return_if_fail (CTK_IS_APPLICATION (application))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return ; } } while (0); |
| 1168 | g_return_if_fail (action_name != NULL)do { if ((action_name != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "action_name != NULL"); return ; } } while (0); |
| 1169 | |
| 1170 | detailed_action_name = g_action_print_detailed_name (action_name, parameter); |
| 1171 | ctk_application_set_accels_for_action (application, detailed_action_name, accelerators); |
| 1172 | g_free (detailed_action_name); |
| 1173 | } |
| 1174 | |
| 1175 | /** |
| 1176 | * ctk_application_prefers_app_menu: |
| 1177 | * @application: a #CtkApplication |
| 1178 | * |
| 1179 | * Determines if the desktop environment in which the application is |
| 1180 | * running would prefer an application menu be shown. |
| 1181 | * |
| 1182 | * If this function returns %TRUE then the application should call |
| 1183 | * ctk_application_set_app_menu() with the contents of an application |
| 1184 | * menu, which will be shown by the desktop environment. If it returns |
| 1185 | * %FALSE then you should consider using an alternate approach, such as |
| 1186 | * a menubar. |
| 1187 | * |
| 1188 | * The value returned by this function is purely advisory and you are |
| 1189 | * free to ignore it. If you call ctk_application_set_app_menu() even |
| 1190 | * if the desktop environment doesn't support app menus, then a fallback |
| 1191 | * will be provided. |
| 1192 | * |
| 1193 | * Applications are similarly free not to set an app menu even if the |
| 1194 | * desktop environment wants to show one. In that case, a fallback will |
| 1195 | * also be created by the desktop environment (GNOME, for example, uses |
| 1196 | * a menu with only a "Quit" item in it). |
| 1197 | * |
| 1198 | * The value returned by this function never changes. Once it returns a |
| 1199 | * particular value, it is guaranteed to always return the same value. |
| 1200 | * |
| 1201 | * You may only call this function after the application has been |
| 1202 | * registered and after the base startup handler has run. You're most |
| 1203 | * likely to want to use this from your own startup handler. It may |
| 1204 | * also make sense to consult this function while constructing UI (in |
| 1205 | * activate, open or an action activation handler) in order to determine |
| 1206 | * if you should show a gear menu or not. |
| 1207 | * |
| 1208 | * This function will return %FALSE on Mac OS and a default app menu |
| 1209 | * will be created automatically with the "usual" contents of that menu |
| 1210 | * typical to most Mac OS applications. If you call |
| 1211 | * ctk_application_set_app_menu() anyway, then this menu will be |
| 1212 | * replaced with your own. |
| 1213 | * |
| 1214 | * Returns: %TRUE if you should set an app menu |
| 1215 | * |
| 1216 | * Since: 3.14 |
| 1217 | **/ |
| 1218 | gboolean |
| 1219 | ctk_application_prefers_app_menu (CtkApplication *application) |
| 1220 | { |
| 1221 | g_return_val_if_fail (CTK_IS_APPLICATION (application), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return ((0)); } } while (0); |
| 1222 | g_return_val_if_fail (application->priv->impl != NULL, FALSE)do { if ((application->priv->impl != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__) ), "application->priv->impl != NULL"); return ((0)); } } while (0); |
| 1223 | |
| 1224 | return ctk_application_impl_prefers_app_menu (application->priv->impl); |
| 1225 | } |
| 1226 | |
| 1227 | /** |
| 1228 | * ctk_application_set_app_menu: |
| 1229 | * @application: a #CtkApplication |
| 1230 | * @app_menu: (allow-none): a #GMenuModel, or %NULL |
| 1231 | * |
| 1232 | * Sets or unsets the application menu for @application. |
| 1233 | * |
| 1234 | * This can only be done in the primary instance of the application, |
| 1235 | * after it has been registered. #GApplication::startup is a good place |
| 1236 | * to call this. |
| 1237 | * |
| 1238 | * The application menu is a single menu containing items that typically |
| 1239 | * impact the application as a whole, rather than acting on a specific |
| 1240 | * window or document. For example, you would expect to see |
| 1241 | * “Preferences” or “Quit” in an application menu, but not “Save” or |
| 1242 | * “Print”. |
| 1243 | * |
| 1244 | * If supported, the application menu will be rendered by the desktop |
| 1245 | * environment. |
| 1246 | * |
| 1247 | * Use the base #GActionMap interface to add actions, to respond to the user |
| 1248 | * selecting these menu items. |
| 1249 | * |
| 1250 | * Since: 3.4 |
| 1251 | */ |
| 1252 | void |
| 1253 | ctk_application_set_app_menu (CtkApplication *application, |
| 1254 | GMenuModel *app_menu) |
| 1255 | { |
| 1256 | g_return_if_fail (CTK_IS_APPLICATION (application))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return ; } } while (0); |
| 1257 | g_return_if_fail (g_application_get_is_registered (G_APPLICATION (application)))do { if ((g_application_get_is_registered (((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((application )), ((g_application_get_type ()))))))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "g_application_get_is_registered (G_APPLICATION (application))" ); return; } } while (0); |
| 1258 | g_return_if_fail (!g_application_get_is_remote (G_APPLICATION (application)))do { if ((!g_application_get_is_remote (((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((application )), ((g_application_get_type ()))))))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "!g_application_get_is_remote (G_APPLICATION (application))" ); return; } } while (0); |
| 1259 | g_return_if_fail (app_menu == NULL || G_IS_MENU_MODEL (app_menu))do { if ((app_menu == ((void*)0) || (((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ((app_menu)); GType __t = ((g_menu_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "app_menu == NULL || G_IS_MENU_MODEL (app_menu)" ); return; } } while (0); |
| 1260 | |
| 1261 | if (g_set_object (&application->priv->app_menu, app_menu)(__extension__ ({ _Static_assert (sizeof *(&application-> priv->app_menu) == sizeof (app_menu), "Expression evaluates to false" ); union { char *in; GObject **out; } _object_ptr; _object_ptr .in = (char *) (&application->priv->app_menu); (void ) (0 ? *(&application->priv->app_menu) = (app_menu) , (0) : (0)); (g_set_object) (_object_ptr.out, (GObject *) app_menu ); }))) |
| 1262 | { |
| 1263 | if (app_menu) |
| 1264 | extract_accels_from_menu (app_menu, application); |
| 1265 | |
| 1266 | ctk_application_impl_set_app_menu (application->priv->impl, app_menu); |
| 1267 | |
| 1268 | g_object_notify_by_pspec (G_OBJECT (application)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), (((GType) ((20) << (2)))))))), ctk_application_props[PROP_APP_MENU]); |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | /** |
| 1273 | * ctk_application_get_app_menu: |
| 1274 | * @application: a #CtkApplication |
| 1275 | * |
| 1276 | * Returns the menu model that has been set with |
| 1277 | * ctk_application_set_app_menu(). |
| 1278 | * |
| 1279 | * Returns: (transfer none) (nullable): the application menu of @application |
| 1280 | * or %NULL if no application menu has been set. |
| 1281 | * |
| 1282 | * Since: 3.4 |
| 1283 | */ |
| 1284 | GMenuModel * |
| 1285 | ctk_application_get_app_menu (CtkApplication *application) |
| 1286 | { |
| 1287 | g_return_val_if_fail (CTK_IS_APPLICATION (application), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return (((void*)0)); } } while (0); |
| 1288 | |
| 1289 | return application->priv->app_menu; |
| 1290 | } |
| 1291 | |
| 1292 | /** |
| 1293 | * ctk_application_set_menubar: |
| 1294 | * @application: a #CtkApplication |
| 1295 | * @menubar: (allow-none): a #GMenuModel, or %NULL |
| 1296 | * |
| 1297 | * Sets or unsets the menubar for windows of @application. |
| 1298 | * |
| 1299 | * This is a menubar in the traditional sense. |
| 1300 | * |
| 1301 | * This can only be done in the primary instance of the application, |
| 1302 | * after it has been registered. #GApplication::startup is a good place |
| 1303 | * to call this. |
| 1304 | * |
| 1305 | * Depending on the desktop environment, this may appear at the top of |
| 1306 | * each window, or at the top of the screen. In some environments, if |
| 1307 | * both the application menu and the menubar are set, the application |
| 1308 | * menu will be presented as if it were the first item of the menubar. |
| 1309 | * Other environments treat the two as completely separate — for example, |
| 1310 | * the application menu may be rendered by the desktop shell while the |
| 1311 | * menubar (if set) remains in each individual window. |
| 1312 | * |
| 1313 | * Use the base #GActionMap interface to add actions, to respond to the |
| 1314 | * user selecting these menu items. |
| 1315 | * |
| 1316 | * Since: 3.4 |
| 1317 | */ |
| 1318 | void |
| 1319 | ctk_application_set_menubar (CtkApplication *application, |
| 1320 | GMenuModel *menubar) |
| 1321 | { |
| 1322 | g_return_if_fail (CTK_IS_APPLICATION (application))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return ; } } while (0); |
| 1323 | g_return_if_fail (g_application_get_is_registered (G_APPLICATION (application)))do { if ((g_application_get_is_registered (((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((application )), ((g_application_get_type ()))))))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "g_application_get_is_registered (G_APPLICATION (application))" ); return; } } while (0); |
| 1324 | g_return_if_fail (!g_application_get_is_remote (G_APPLICATION (application)))do { if ((!g_application_get_is_remote (((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((application )), ((g_application_get_type ()))))))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "!g_application_get_is_remote (G_APPLICATION (application))" ); return; } } while (0); |
| 1325 | g_return_if_fail (menubar == NULL || G_IS_MENU_MODEL (menubar))do { if ((menubar == ((void*)0) || (((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ((menubar)); GType __t = ((g_menu_model_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "menubar == NULL || G_IS_MENU_MODEL (menubar)" ); return; } } while (0); |
| 1326 | |
| 1327 | if (g_set_object (&application->priv->menubar, menubar)(__extension__ ({ _Static_assert (sizeof *(&application-> priv->menubar) == sizeof (menubar), "Expression evaluates to false" ); union { char *in; GObject **out; } _object_ptr; _object_ptr .in = (char *) (&application->priv->menubar); (void ) (0 ? *(&application->priv->menubar) = (menubar), ( 0) : (0)); (g_set_object) (_object_ptr.out, (GObject *) menubar ); }))) |
| 1328 | { |
| 1329 | if (menubar) |
| 1330 | extract_accels_from_menu (menubar, application); |
| 1331 | |
| 1332 | ctk_application_impl_set_menubar (application->priv->impl, menubar); |
| 1333 | |
| 1334 | g_object_notify_by_pspec (G_OBJECT (application)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), (((GType) ((20) << (2)))))))), ctk_application_props[PROP_MENUBAR]); |
| 1335 | } |
| 1336 | } |
| 1337 | |
| 1338 | /** |
| 1339 | * ctk_application_get_menubar: |
| 1340 | * @application: a #CtkApplication |
| 1341 | * |
| 1342 | * Returns the menu model that has been set with |
| 1343 | * ctk_application_set_menubar(). |
| 1344 | * |
| 1345 | * Returns: (transfer none): the menubar for windows of @application |
| 1346 | * |
| 1347 | * Since: 3.4 |
| 1348 | */ |
| 1349 | GMenuModel * |
| 1350 | ctk_application_get_menubar (CtkApplication *application) |
| 1351 | { |
| 1352 | g_return_val_if_fail (CTK_IS_APPLICATION (application), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return (((void*)0)); } } while (0); |
| 1353 | |
| 1354 | return application->priv->menubar; |
| 1355 | } |
| 1356 | |
| 1357 | /** |
| 1358 | * CtkApplicationInhibitFlags: |
| 1359 | * @CTK_APPLICATION_INHIBIT_LOGOUT: Inhibit ending the user session |
| 1360 | * by logging out or by shutting down the computer |
| 1361 | * @CTK_APPLICATION_INHIBIT_SWITCH: Inhibit user switching |
| 1362 | * @CTK_APPLICATION_INHIBIT_SUSPEND: Inhibit suspending the |
| 1363 | * session or computer |
| 1364 | * @CTK_APPLICATION_INHIBIT_IDLE: Inhibit the session being |
| 1365 | * marked as idle (and possibly locked) |
| 1366 | * |
| 1367 | * Types of user actions that may be blocked by ctk_application_inhibit(). |
| 1368 | * |
| 1369 | * Since: 3.4 |
| 1370 | */ |
| 1371 | |
| 1372 | /** |
| 1373 | * ctk_application_inhibit: |
| 1374 | * @application: the #CtkApplication |
| 1375 | * @window: (allow-none): a #CtkWindow, or %NULL |
| 1376 | * @flags: what types of actions should be inhibited |
| 1377 | * @reason: (allow-none): a short, human-readable string that explains |
| 1378 | * why these operations are inhibited |
| 1379 | * |
| 1380 | * Inform the session manager that certain types of actions should be |
| 1381 | * inhibited. This is not guaranteed to work on all platforms and for |
| 1382 | * all types of actions. |
| 1383 | * |
| 1384 | * Applications should invoke this method when they begin an operation |
| 1385 | * that should not be interrupted, such as creating a CD or DVD. The |
| 1386 | * types of actions that may be blocked are specified by the @flags |
| 1387 | * parameter. When the application completes the operation it should |
| 1388 | * call ctk_application_uninhibit() to remove the inhibitor. Note that |
| 1389 | * an application can have multiple inhibitors, and all of them must |
| 1390 | * be individually removed. Inhibitors are also cleared when the |
| 1391 | * application exits. |
| 1392 | * |
| 1393 | * Applications should not expect that they will always be able to block |
| 1394 | * the action. In most cases, users will be given the option to force |
| 1395 | * the action to take place. |
| 1396 | * |
| 1397 | * Reasons should be short and to the point. |
| 1398 | * |
| 1399 | * If @window is given, the session manager may point the user to |
| 1400 | * this window to find out more about why the action is inhibited. |
| 1401 | * |
| 1402 | * Returns: A non-zero cookie that is used to uniquely identify this |
| 1403 | * request. It should be used as an argument to ctk_application_uninhibit() |
| 1404 | * in order to remove the request. If the platform does not support |
| 1405 | * inhibiting or the request failed for some reason, 0 is returned. |
| 1406 | * |
| 1407 | * Since: 3.4 |
| 1408 | */ |
| 1409 | guint |
| 1410 | ctk_application_inhibit (CtkApplication *application, |
| 1411 | CtkWindow *window, |
| 1412 | CtkApplicationInhibitFlags flags, |
| 1413 | const gchar *reason) |
| 1414 | { |
| 1415 | g_return_val_if_fail (CTK_IS_APPLICATION (application), 0)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return (0); } } while (0); |
| 1416 | g_return_val_if_fail (!g_application_get_is_remote (G_APPLICATION (application)), 0)do { if ((!g_application_get_is_remote (((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((application )), ((g_application_get_type ()))))))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "!g_application_get_is_remote (G_APPLICATION (application))" ); return (0); } } while (0); |
| 1417 | g_return_val_if_fail (window == NULL || CTK_IS_WINDOW (window), 0)do { if ((window == ((void*)0) || (((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ((window)); GType __t = ((ctk_window_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "window == NULL || CTK_IS_WINDOW (window)" ); return (0); } } while (0); |
| 1418 | |
| 1419 | return ctk_application_impl_inhibit (application->priv->impl, window, flags, reason); |
| 1420 | } |
| 1421 | |
| 1422 | /** |
| 1423 | * ctk_application_uninhibit: |
| 1424 | * @application: the #CtkApplication |
| 1425 | * @cookie: a cookie that was returned by ctk_application_inhibit() |
| 1426 | * |
| 1427 | * Removes an inhibitor that has been established with ctk_application_inhibit(). |
| 1428 | * Inhibitors are also cleared when the application exits. |
| 1429 | * |
| 1430 | * Since: 3.4 |
| 1431 | */ |
| 1432 | void |
| 1433 | ctk_application_uninhibit (CtkApplication *application, |
| 1434 | guint cookie) |
| 1435 | { |
| 1436 | g_return_if_fail (CTK_IS_APPLICATION (application))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return ; } } while (0); |
| 1437 | g_return_if_fail (!g_application_get_is_remote (G_APPLICATION (application)))do { if ((!g_application_get_is_remote (((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((application )), ((g_application_get_type ()))))))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "!g_application_get_is_remote (G_APPLICATION (application))" ); return; } } while (0); |
| 1438 | g_return_if_fail (cookie > 0)do { if ((cookie > 0)) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "cookie > 0"); return ; } } while (0); |
| 1439 | |
| 1440 | ctk_application_impl_uninhibit (application->priv->impl, cookie); |
| 1441 | } |
| 1442 | |
| 1443 | /** |
| 1444 | * ctk_application_is_inhibited: |
| 1445 | * @application: the #CtkApplication |
| 1446 | * @flags: what types of actions should be queried |
| 1447 | * |
| 1448 | * Determines if any of the actions specified in @flags are |
| 1449 | * currently inhibited (possibly by another application). |
| 1450 | * |
| 1451 | * Note that this information may not be available (for example |
| 1452 | * when the application is running in a sandbox). |
| 1453 | * |
| 1454 | * Returns: %TRUE if any of the actions specified in @flags are inhibited |
| 1455 | * |
| 1456 | * Since: 3.4 |
| 1457 | */ |
| 1458 | gboolean |
| 1459 | ctk_application_is_inhibited (CtkApplication *application, |
| 1460 | CtkApplicationInhibitFlags flags) |
| 1461 | { |
| 1462 | g_return_val_if_fail (CTK_IS_APPLICATION (application), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return ((0)); } } while (0); |
| 1463 | g_return_val_if_fail (!g_application_get_is_remote (G_APPLICATION (application)), FALSE)do { if ((!g_application_get_is_remote (((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((application )), ((g_application_get_type ()))))))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "!g_application_get_is_remote (G_APPLICATION (application))" ); return ((0)); } } while (0); |
| 1464 | |
| 1465 | return ctk_application_impl_is_inhibited (application->priv->impl, flags); |
| 1466 | } |
| 1467 | |
| 1468 | CtkActionMuxer * |
| 1469 | ctk_application_get_parent_muxer_for_window (CtkWindow *window) |
| 1470 | { |
| 1471 | CtkApplication *application; |
| 1472 | |
| 1473 | application = ctk_window_get_application (window); |
| 1474 | |
| 1475 | if (!application) |
| 1476 | return NULL((void*)0); |
| 1477 | |
| 1478 | return application->priv->muxer; |
| 1479 | } |
| 1480 | |
| 1481 | CtkApplicationAccels * |
| 1482 | ctk_application_get_application_accels (CtkApplication *application) |
| 1483 | { |
| 1484 | return application->priv->accels; |
| 1485 | } |
| 1486 | |
| 1487 | /** |
| 1488 | * ctk_application_list_action_descriptions: |
| 1489 | * @application: a #CtkApplication |
| 1490 | * |
| 1491 | * Lists the detailed action names which have associated accelerators. |
| 1492 | * See ctk_application_set_accels_for_action(). |
| 1493 | * |
| 1494 | * Returns: (transfer full): a %NULL-terminated array of strings, |
| 1495 | * free with g_strfreev() when done |
| 1496 | * |
| 1497 | * Since: 3.12 |
| 1498 | */ |
| 1499 | gchar ** |
| 1500 | ctk_application_list_action_descriptions (CtkApplication *application) |
| 1501 | { |
| 1502 | g_return_val_if_fail (CTK_IS_APPLICATION (application), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return (((void*)0)); } } while (0); |
| 1503 | |
| 1504 | return ctk_application_accels_list_action_descriptions (application->priv->accels); |
| 1505 | } |
| 1506 | |
| 1507 | /** |
| 1508 | * ctk_application_set_accels_for_action: |
| 1509 | * @application: a #CtkApplication |
| 1510 | * @detailed_action_name: a detailed action name, specifying an action |
| 1511 | * and target to associate accelerators with |
| 1512 | * @accels: (array zero-terminated=1): a list of accelerators in the format |
| 1513 | * understood by ctk_accelerator_parse() |
| 1514 | * |
| 1515 | * Sets zero or more keyboard accelerators that will trigger the |
| 1516 | * given action. The first item in @accels will be the primary |
| 1517 | * accelerator, which may be displayed in the UI. |
| 1518 | * |
| 1519 | * To remove all accelerators for an action, use an empty, zero-terminated |
| 1520 | * array for @accels. |
| 1521 | * |
| 1522 | * For the @detailed_action_name, see g_action_parse_detailed_name() and |
| 1523 | * g_action_print_detailed_name(). |
| 1524 | * |
| 1525 | * Since: 3.12 |
| 1526 | */ |
| 1527 | void |
| 1528 | ctk_application_set_accels_for_action (CtkApplication *application, |
| 1529 | const gchar *detailed_action_name, |
| 1530 | const gchar * const *accels) |
| 1531 | { |
| 1532 | gchar *action_and_target; |
| 1533 | |
| 1534 | g_return_if_fail (CTK_IS_APPLICATION (application))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return ; } } while (0); |
| 1535 | g_return_if_fail (detailed_action_name != NULL)do { if ((detailed_action_name != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "detailed_action_name != NULL" ); return; } } while (0); |
| 1536 | g_return_if_fail (accels != NULL)do { if ((accels != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "accels != NULL"); return ; } } while (0); |
| 1537 | |
| 1538 | ctk_application_accels_set_accels_for_action (application->priv->accels, |
| 1539 | detailed_action_name, |
| 1540 | accels); |
| 1541 | |
| 1542 | action_and_target = ctk_normalise_detailed_action_name (detailed_action_name); |
| 1543 | ctk_action_muxer_set_primary_accel (application->priv->muxer, action_and_target, accels[0]); |
| 1544 | g_free (action_and_target); |
| 1545 | |
| 1546 | ctk_application_update_accels (application); |
| 1547 | } |
| 1548 | |
| 1549 | /** |
| 1550 | * ctk_application_get_accels_for_action: |
| 1551 | * @application: a #CtkApplication |
| 1552 | * @detailed_action_name: a detailed action name, specifying an action |
| 1553 | * and target to obtain accelerators for |
| 1554 | * |
| 1555 | * Gets the accelerators that are currently associated with |
| 1556 | * the given action. |
| 1557 | * |
| 1558 | * Returns: (transfer full): accelerators for @detailed_action_name, as |
| 1559 | * a %NULL-terminated array. Free with g_strfreev() when no longer needed |
| 1560 | * |
| 1561 | * Since: 3.12 |
| 1562 | */ |
| 1563 | gchar ** |
| 1564 | ctk_application_get_accels_for_action (CtkApplication *application, |
| 1565 | const gchar *detailed_action_name) |
| 1566 | { |
| 1567 | g_return_val_if_fail (CTK_IS_APPLICATION (application), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return (((void*)0)); } } while (0); |
| 1568 | g_return_val_if_fail (detailed_action_name != NULL, NULL)do { if ((detailed_action_name != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "detailed_action_name != NULL" ); return (((void*)0)); } } while (0); |
| 1569 | |
| 1570 | return ctk_application_accels_get_accels_for_action (application->priv->accels, |
| 1571 | detailed_action_name); |
| 1572 | } |
| 1573 | |
| 1574 | /** |
| 1575 | * ctk_application_get_actions_for_accel: |
| 1576 | * @application: a #CtkApplication |
| 1577 | * @accel: an accelerator that can be parsed by ctk_accelerator_parse() |
| 1578 | * |
| 1579 | * Returns the list of actions (possibly empty) that @accel maps to. |
| 1580 | * Each item in the list is a detailed action name in the usual form. |
| 1581 | * |
| 1582 | * This might be useful to discover if an accel already exists in |
| 1583 | * order to prevent installation of a conflicting accelerator (from |
| 1584 | * an accelerator editor or a plugin system, for example). Note that |
| 1585 | * having more than one action per accelerator may not be a bad thing |
| 1586 | * and might make sense in cases where the actions never appear in the |
| 1587 | * same context. |
| 1588 | * |
| 1589 | * In case there are no actions for a given accelerator, an empty array |
| 1590 | * is returned. %NULL is never returned. |
| 1591 | * |
| 1592 | * It is a programmer error to pass an invalid accelerator string. |
| 1593 | * If you are unsure, check it with ctk_accelerator_parse() first. |
| 1594 | * |
| 1595 | * Returns: (transfer full): a %NULL-terminated array of actions for @accel |
| 1596 | * |
| 1597 | * Since: 3.14 |
| 1598 | */ |
| 1599 | gchar ** |
| 1600 | ctk_application_get_actions_for_accel (CtkApplication *application, |
| 1601 | const gchar *accel) |
| 1602 | { |
| 1603 | g_return_val_if_fail (CTK_IS_APPLICATION (application), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return (((void*)0)); } } while (0); |
| 1604 | g_return_val_if_fail (accel != NULL, NULL)do { if ((accel != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "accel != NULL"); return (((void*)0)); } } while (0); |
| 1605 | |
| 1606 | return ctk_application_accels_get_actions_for_accel (application->priv->accels, accel); |
| 1607 | } |
| 1608 | |
| 1609 | CtkActionMuxer * |
| 1610 | ctk_application_get_action_muxer (CtkApplication *application) |
| 1611 | { |
| 1612 | g_assert (application->priv->muxer)do { if (application->priv->muxer) ; else g_assertion_message_expr ("Ctk", "ctkapplication.c", 1612, ((const char*) (__func__)) , "application->priv->muxer"); } while (0); |
| 1613 | |
| 1614 | return application->priv->muxer; |
| 1615 | } |
| 1616 | |
| 1617 | void |
| 1618 | ctk_application_insert_action_group (CtkApplication *application, |
| 1619 | const gchar *name, |
| 1620 | GActionGroup *action_group) |
| 1621 | { |
| 1622 | ctk_action_muxer_insert (application->priv->muxer, name, action_group); |
| 1623 | } |
| 1624 | |
| 1625 | void |
| 1626 | ctk_application_handle_window_realize (CtkApplication *application, |
| 1627 | CtkWindow *window) |
| 1628 | { |
| 1629 | if (application->priv->impl) |
| 1630 | ctk_application_impl_handle_window_realize (application->priv->impl, window); |
| 1631 | } |
| 1632 | |
| 1633 | void |
| 1634 | ctk_application_handle_window_map (CtkApplication *application, |
| 1635 | CtkWindow *window) |
| 1636 | { |
| 1637 | if (application->priv->impl) |
| 1638 | ctk_application_impl_handle_window_map (application->priv->impl, window); |
| 1639 | } |
| 1640 | |
| 1641 | /** |
| 1642 | * ctk_application_get_menu_by_id: |
| 1643 | * @application: a #CtkApplication |
| 1644 | * @id: the id of the menu to look up |
| 1645 | * |
| 1646 | * Gets a menu from automatically loaded resources. |
| 1647 | * See [Automatic resources][automatic-resources] |
| 1648 | * for more information. |
| 1649 | * |
| 1650 | * Returns: (transfer none): Gets the menu with the |
| 1651 | * given id from the automatically loaded resources |
| 1652 | * |
| 1653 | * Since: 3.14 |
| 1654 | */ |
| 1655 | GMenu * |
| 1656 | ctk_application_get_menu_by_id (CtkApplication *application, |
| 1657 | const gchar *id) |
| 1658 | { |
| 1659 | GObject *object; |
| 1660 | |
| 1661 | g_return_val_if_fail (CTK_IS_APPLICATION (application), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((application)); GType __t = ((ctk_application_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_APPLICATION (application)"); return (((void*)0)); } } while (0); |
| 1662 | g_return_val_if_fail (id != NULL, NULL)do { if ((id != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "id != NULL"); return (( (void*)0)); } } while (0); |
| 1663 | |
| 1664 | if (!application->priv->menus_builder) |
| 1665 | return NULL((void*)0); |
| 1666 | |
| 1667 | object = ctk_builder_get_object (application->priv->menus_builder, id); |
| 1668 | |
| 1669 | if (!object || !G_IS_MENU (object)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (object)); GType __t = ((g_menu_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst ->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) |
| 1670 | return NULL((void*)0); |
| 1671 | |
| 1672 | return G_MENU (object)((((GMenu*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((g_menu_get_type ())))))); |
| 1673 | } |
| 1674 | |
| 1675 | void |
| 1676 | ctk_application_set_screensaver_active (CtkApplication *application, |
| 1677 | gboolean active) |
| 1678 | { |
| 1679 | CtkApplicationPrivate *priv = ctk_application_get_instance_private (application); |
| 1680 | |
| 1681 | if (priv->screensaver_active != active) |
| 1682 | { |
| 1683 | priv->screensaver_active = active; |
| 1684 | g_object_notify (G_OBJECT (application)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((application)), (((GType) ((20) << (2)))))))), "screensaver-active"); |
| 1685 | } |
| 1686 | } |