Module: Lich::Common::GtkMainLoopGuards

Included in:
Lich::Common
Defined in:
documented/common/gtk.rb

Overview

Lich owns the shared GTK main loop. Scripts may create and show windows, but redundant Gtk.main / Gtk.main_quit calls can destabilize every GTK script in the process.

Instance Method Summary collapse

Instance Method Details

#lich_main_quit(*args) ⇒ Object?

Explicit escape hatch for core-owned shutdown paths.

No-ops unless a GTK main loop is nested. Also fails closed when main_level is unavailable -- gtk_main_quit asserts main_loops != NULL and emits Gtk-CRITICAL otherwise.

Parameters:

  • args (Array)

    arguments forwarded to GTK

Returns:

  • (Object, nil)

    GTK return value, or nil when quitting is unsafe



414
415
416
417
418
# File 'documented/common/gtk.rb', line 414

def lich_main_quit(*args)
  return nil unless respond_to?(:main_level) && main_level.to_i > 0

  Lich::Common.allow_gtk_main_quit { main_quit(*args) }
end

#main(*args) ⇒ Object?

Starts the GTK main loop only when Lich has not already started it.

Parameters:

  • args (Array)

    arguments forwarded to GTK

Returns:

  • (Object, nil)

    GTK return value, or nil when the call is ignored



382
383
384
385
386
387
388
389
# File 'documented/common/gtk.rb', line 382

def main(*args)
  if respond_to?(:main_level) && main_level.to_i > 0
    Lich.log "info: Ignoring redundant Gtk.main request while GTK main loop is already running (#{Lich::Common.gtk_guard_context})"
    return nil
  end

  super(*args)
end

#main_quitObject?

Prevents scripts from stopping the shared GTK main loop.

Core-owned shutdown paths must use #lich_main_quit instead.

Returns:

  • (Object, nil)

    GTK return value for core-owned shutdown, or nil when ignored



396
397
398
399
400
401
402
403
404
# File 'documented/common/gtk.rb', line 396

def main_quit(*)
  return super if Thread.current[:lich_allow_gtk_main_quit]

  if respond_to?(:main_level) && main_level.to_i > 0
    Lich.log "info: Ignoring Gtk.main_quit request from shared GTK script context (#{Lich::Common.gtk_guard_context})"
  end

  nil
end