View difference between Paste ID: Pf2F3m29 and feq4tzBP
SHOW: | | - or go back to the newest paste.
1
2
require 'gtk2'
3
4
#setup some helper functions to block so the script doesn't exit before we've had a chance to see the behavior
5
if !defined?(wait_until)
6
    def wait_until(announce=nil)
7
        priosave = Thread.current.priority
8
        Thread.current.priority = 0
9
        unless announce.nil? or yield
10-
            respond(announce)
10+
            puts(announce)
11
        end
12
        until yield
13
            sleep 0.25
14
        end
15
        Thread.current.priority = priosave
16
    end
17
18
    def wait_while(announce=nil)
19
        priosave = Thread.current.priority
20
        Thread.current.priority = 0
21
        unless announce.nil? or !yield
22-
            respond(announce)
22+
            puts(announce)
23
        end
24
        while yield
25
            sleep 0.25
26
        end
27
        Thread.current.priority = priosave
28
    end
29
30
end
31
32
if defined?(Gtk) && !defined?(Gtk.queue)
33
    module Gtk
34
        # Calling Gtk API in a thread other than the main thread may cause random segfaults
35
        def Gtk.queue &block
36
            GLib::Timeout.add(1) {
37
                begin
38
                    block.call
39
                rescue
40-
                    respond "error in Gtk.queue: #{$!}"
40+
                    puts "error in Gtk.queue: #{$!}"
41-
                    Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
41+
42
                    puts "error in Gtk.queue: #{$!}"
43-
                    respond "error in Gtk.queue: #{$!}"
43+
44-
                    Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
44+
45
                rescue SecurityError
46
                    puts "error in Gtk.queue: #{$!}"
47
                rescue ThreadError
48-
                    respond "error in Gtk.queue: #{$!}"
48+
                    puts "error in Gtk.queue: #{$!}"
49-
                    Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
49+
50
                    puts "error in Gtk.queue: #{$!}"
51-
                    respond "error in Gtk.queue: #{$!}"
51+
52-
                    Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
52+
                    puts "error in Gtk.queue: #{$!}"
53
                rescue ScriptError
54-
                    respond "error in Gtk.queue: #{$!}"
54+
                    puts "error in Gtk.queue: #{$!}"
55-
                    Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
55+
56
                    puts "error in Gtk.queue: #{$!}"
57-
                    respond "error in Gtk.queue: #{$!}"
57+
58-
                    Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
58+
                    puts "error in Gtk.queue: #{$!}"
59
                rescue
60-
                    respond "error in Gtk.queue: #{$!}"
60+
                    puts "error in Gtk.queue: #{$!}"
61-
                    Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
61+
62
                false # don't repeat timeout
63-
                    respond "error in Gtk.queue: #{$!}"
63+
64-
                    Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
64+
65
    end
66-
                    respond "error in Gtk.queue: #{$!}"
66+
67-
                    Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
67+
68
69-
                    respond "error in Gtk.queue: #{$!}"
69+
70-
                    Lich.log "error in Gtk.queue: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
70+
71
window_position    = [ 0, 0 ]
72
73
narost_exit     = false
74
window_resized  = true
75
start           = nil
76
77
window          = nil
78
79
require 'pp'
80
81
Gtk.queue {
82
    window = Gtk::Window.new
83-
scale           = nil
83+
84-
map_offset_x    = nil
84+
85-
map_offset_y    = nil
85+
86
    window.show_all
87
88
    window_width = [window_width,100].max
89
    window_height = [window_height,100].max
90
    window.resize(window_width, window_height)
91
92
    window_position[0] = [0, (Gdk.screen_width - window_width)].min
93
    window_position[1] = [0, (Gdk.screen_height - window_height)].min
94
95
    window.move(window_position[0], window_position[1])
96
97
    start = true
98
}
99
100
thread = Thread.new {
101
    # Create a second thread as our window event processor
102
    Gtk.main
103-
    window_position[0] = [[0, window_position[0].to_i].max, (Gdk.screen_width-window_width)].min
103+
104-
    window_position[1] = [[0, window_position[1].to_i].max, (Gdk.screen_height-window_height)].min
104+
105
# Wait for the window to open
106
wait_until { start }
107
108
# Wait until the window is closed
109
wait_while { !narost_exit }