File: mainloop.rb

package info (click to toggle)
mikutter 5.0.4%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,700 kB
  • sloc: ruby: 21,307; sh: 181; makefile: 19
file content (48 lines) | stat: -rw-r--r-- 991 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# -*- coding: utf-8 -*-

module Mainloop

  TICK_MAX = 20
  TICK_MIN = 2

  def mainloop
    @exit_flag = false
    catch(:__exit_mikutter) do
      tick = TICK_MAX
      loop do
        if tick > TICK_MIN
          tick -= 1
        end
        if Gtk.events_pending?
          tick = TICK_MAX + 1
          Gtk.main_iteration
          throw :__exit_mikutter if @exit_flag || Gtk.exception
        end
        unless Delayer.empty?
          tick = TICK_MAX + 1
          Delayer.run_once
          throw :__exit_mikutter if @exit_flag || Gtk.exception
        end
        sleep(1.0 / tick) if tick <= TICK_MAX
      end
    end
  rescue Interrupt,SystemExit,SignalException => exception
    raise exception
  rescue Exception => exception
    Gtk.exception = exception
  ensure
    SerialThreadGroup.force_exit!
  end

  def exception_filter(e)
    Gtk.exception ? Gtk.exception : e
  end

  def reserve_exit
    @exit_flag = true
  end

  def exit!
    throw(:__exit_mikutter)
  end
end