• R/O
  • HTTP
  • SSH
  • HTTPS

ruby-gtk3: Commit

Ruby GTK3移行後のメインリポジトリ


Commit MetaInfo

Revision57dc26d0b131baddc3b57fb4b723c3dba63ec32a (tree)
Time2019-01-06 22:22:58
AuthorShyouzou Sugitani <shy@user...>
CommiterShyouzou Sugitani

Log Message

introduce Gtk::ApplicationWindow

Change Summary

Incremental Difference

--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
11 Sun January 6 2019 Shyouzou Sugitani <shy@users.osdn.me>
2+ * Gtk::ApplicationWindowを生成し、画面サイズ算出に利用するようにした.
23 * Gtk::Applicationを使用するようにした.
34 * AYA, AYA5互換モジュールにおいてFixnum(deprecated)を
45 使用しないよう修正した.
--- a/lib/ninix/balloon.rb
+++ b/lib/ninix/balloon.rb
@@ -798,7 +798,7 @@ module Balloon
798798 x = (base_x + px)
799799 end
800800 y = (base_y + py)
801- left, top, scrn_w, scrn_h = @window.workarea
801+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
802802 if (y + h) > scrn_h # XXX
803803 y = (scrn_h - h)
804804 end
@@ -1537,7 +1537,7 @@ module Balloon
15371537 Gtk::StateFlags::NORMAL, Gdk::RGBA.new(0, 0, 0, 0))
15381538 w = desc.get('communicatebox.width', :default => 250).to_i
15391539 h = desc.get('communicatebox.height', :default => -1).to_i
1540- left, top, scrn_w, scrn_h = @window.workarea
1540+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
15411541 @__surface_position = [(scrn_w - w) / 2, (scrn_h - h) / 2] # XXX
15421542 @entry = Gtk::Entry.new
15431543 @entry.signal_connect('activate') do |w|
--- a/lib/ninix/dll/bln.rb
+++ b/lib/ninix/dll/bln.rb
@@ -210,7 +210,7 @@ module Bln
210210 else
211211 @position = 'sakura'
212212 end
213- left, top, scrn_w, scrn_h = @window.workarea
213+ left, top, scrn_w, scrn_h = @__sakura.get_workarea
214214 # -1: left, 1: right
215215 if @position == 'sakura'
216216 s0_x, s0_y, s0_w, s0_h = get_sakura_status('SurfaceSakura')
@@ -501,7 +501,7 @@ module Bln
501501 end
502502
503503 def get_coordinate(w, h)
504- left, top, scrn_w, scrn_h = @window.workarea
504+ left, top, scrn_w, scrn_h = @__sakura.get_workarea
505505 s0_x, s0_y, s0_w, s0_h = get_sakura_status('SurfaceSakura')
506506 s1_x, s1_y, s1_w, s1_h = get_sakura_status('SurfaceKero')
507507 b0_x, b0_y, b0_w, b0_h = get_sakura_status('BalloonSakura')
--- a/lib/ninix/dll/osuwari.rb
+++ b/lib/ninix/dll/osuwari.rb
@@ -103,7 +103,7 @@ module Osuwari
103103 def do_idle_tasks
104104 return false if @timeout_id.nil?
105105 target = @settings['target']
106- left, top, scrn_w, scrn_h = @__sakura.get_workarea(0) # XXX
106+ left, top, scrn_w, scrn_h = @__sakura.get_workarea
107107 target_flag = [false, false]
108108 if target == 'ACTIVE'
109109 active_window = get_active_window()
--- a/lib/ninix/dll/wmove.rb
+++ b/lib/ninix/dll/wmove.rb
@@ -142,7 +142,7 @@ module Wmove
142142 end
143143 elsif name == 'GET_DESKTOP_SIZE'
144144 begin
145- left, top, scrn_w, scrn_h = @__sakura.get_workarea(0) # XXX
145+ left, top, scrn_w, scrn_h = @__sakura.get_workarea
146146 result = ("SAORI/1.0 200 OK\r\n" \
147147 + "Result: " + scrn_w.to_s + "\r\n" \
148148 + "Value0: " + scrn_w.to_s + "\r\n" \
@@ -194,7 +194,7 @@ module Wmove
194194 speed = args[1].to_i
195195 if command == 'MOVE_INSIDE'
196196 w, h = @__sakura.get_surface_size(side)
197- left, top, scrn_w, scrn_h = @__sakura.get_workarea(side)
197+ left, top, scrn_w, scrn_h = @__sakura.get_workarea
198198 if vx < 0 and x + vx <0
199199 vx = [-x, 0].min
200200 elsif vx > 0 and x + vx + w > left + scrn_w
@@ -222,7 +222,7 @@ module Wmove
222222 speed = args[1].to_i
223223 if command == 'MOVETO_INSIDE'
224224 w, h = @__sakura.get_surface_size(side)
225- left, top, scrn_w, scrn_h = @__sakura.get_workarea(side)
225+ left, top, scrn_w, scrn_h = @__sakura.get_workarea
226226 if to < 0
227227 to = 0
228228 elsif to > left + scrn_w - w
--- a/lib/ninix/nekodorif.rb
+++ b/lib/ninix/nekodorif.rb
@@ -150,6 +150,7 @@ module Nekodorif
150150 scale = @target.get_surface_scale()
151151 @skin = Skin.new(@dir, @accelgroup, scale)
152152 @skin.set_responsible(self)
153+ @skin.setup
153154 return 0 if @skin.nil?
154155 @katochan_list = katochan
155156 @katochan = nil
@@ -164,6 +165,7 @@ module Nekodorif
164165 handlers = {
165166 'get_katochan_list' => lambda { return @katochan_list },
166167 'get_mode' => lambda { return @mode },
168+ 'get_workarea' => lambda { return @target.get_workarea },
167169 }
168170 if handlers.include?(event)
169171 result = handlers[event].call # no argument
@@ -302,9 +304,6 @@ module Nekodorif
302304 next true
303305 end
304306 @id = [0, nil]
305- set_surface()
306- set_position(:reset => 1)
307- @window.show_all()
308307 end
309308
310309 def set_responsible(parent)
@@ -327,6 +326,12 @@ module Nekodorif
327326 return result if event_type == 'GET'
328327 end
329328
329+ def setup
330+ set_surface()
331+ set_position(:reset => 1)
332+ @window.show_all()
333+ end
334+
330335 def set_scale(scale)
331336 @__scale = scale
332337 set_surface()
@@ -402,7 +407,7 @@ module Nekodorif
402407 end
403408
404409 def set_position(reset: 0)
405- left, top, scrn_w, scrn_h = @window.workarea
410+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
406411 unless reset.zero?
407412 @x = left
408413 @y = (top + scrn_h - @h)
@@ -621,7 +626,7 @@ module Nekodorif
621626 return if @settings['state'] != 'before'
622627 target_x, target_y = @target.get_surface_position(@side)
623628 target_w, target_h = @target.get_surface_size(@side)
624- left, top, scrn_w, scrn_h = @window.workarea
629+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
625630 @x = (target_x + target_w / 2 - @w / 2 + (@offset_x * @__scale / 100).to_i)
626631 @y = (top + (@offset_y * @__scale / 100).to_i)
627632 @window.move(@x, @y)
@@ -782,7 +787,7 @@ module Nekodorif
782787 end
783788
784789 def check_mikire
785- left, top, scrn_w, scrn_h = @window.workarea
790+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
786791 if (@x + @w - @w / 3) > (left + scrn_w) or \
787792 (@x + @w / 3) < left or \
788793 (@y + @h - @h / 3) > (top + scrn_h) or \
--- a/lib/ninix/pix.rb
+++ b/lib/ninix/pix.rb
@@ -83,7 +83,7 @@ module Pix
8383
8484 class BaseTransparentWindow < Gtk::Window
8585 alias :base_move :move
86- attr_reader :workarea, :supports_alpha
86+ attr_reader :supports_alpha
8787
8888 def initialize(type: Gtk::WindowType::TOPLEVEL)
8989 super(type)
@@ -105,12 +105,6 @@ module Pix
105105 end
106106 @supports_alpha = composited?
107107 fail "assert" unless not visual.nil?
108- if realized?
109- workarea = screen.display.get_monitor_at_window(window).workarea # XXX
110- else
111- workarea = screen.display.get_monitor(0).workarea # XXX
112- end
113- @workarea = [0, 0, workarea.width, workarea.height]
114108 maximize # not fullscreen
115109 end
116110 end
@@ -200,6 +194,36 @@ module Pix
200194 end
201195
202196
197+ class TransparentApplicationWindow < Gtk::ApplicationWindow
198+
199+ def initialize(application)
200+ super(application)
201+ set_decorated(false)
202+ set_app_paintable(true)
203+ set_focus_on_map(false)
204+ if composited?
205+ input_shape_combine_region(Cairo::Region.new) # empty region
206+ end
207+ signal_connect("screen-changed") do |widget, old_screen|
208+ screen_changed(widget, :old_screen => old_screen)
209+ next true
210+ end
211+ screen_changed(self)
212+ end
213+
214+ def screen_changed(widget, old_screen: nil)
215+ if composited?
216+ set_visual(screen.rgba_visual)
217+ else
218+ set_visual(screen.system_visual)
219+ Logging::Logging.debug("screen does NOT support alpha.\n")
220+ end
221+ fail "assert" unless not visual.nil?
222+ maximize # not fullscreen
223+ end
224+ end
225+
226+
203227 def self.get_png_size(path)
204228 return 0, 0 if not File.exists?(path)
205229 buf =
--- a/lib/ninix/sakura.rb
+++ b/lib/ninix/sakura.rb
@@ -577,8 +577,8 @@ module Sakura
577577 @balloon.reset_balloon()
578578 end
579579
580- def get_workarea(side)
581- @surface.get_workarea(side)
580+ def get_workarea
581+ @parent.handle_request('GET', 'get_workarea')
582582 end
583583
584584 def get_surface_position(side)
@@ -867,7 +867,7 @@ module Sakura
867867 :default => default)
868868 end
869869 end
870- left, top, scrn_w, scrn_h = @surface.get_workarea(0) # XXX
870+ left, top, scrn_w, scrn_h = get_workarea
871871 notify_event('OnDisplayChange',
872872 Gdk::Visual.best_depth,
873873 scrn_w, scrn_h, :event_type => 'NOTIFY')
@@ -1964,7 +1964,7 @@ module Sakura
19641964 end
19651965 w, h = get_surface_size(@script_side)
19661966 x, y = get_surface_position(@script_side)
1967- left, top, scrn_w, scrn_h = @surface.get_workarea(@script_side)
1967+ left, top, scrn_w, scrn_h = get_workarea
19681968 if (sx + (sw / 2).to_i) > (left + (scrn_w / 2).to_i)
19691969 new_x = [x - (scrn_w / 20).to_i, sx - (scrn_w / 20).to_i].min
19701970 else
@@ -1994,7 +1994,7 @@ module Sakura
19941994 end
19951995 w, h = get_surface_size(@script_side)
19961996 x, y = get_surface_position(@script_side)
1997- left, top, scrn_w, scrn_h = @surface.get_workarea(@script_side)
1997+ left, top, scrn_w, scrn_h = get_workarea
19981998 if (x < (sx + (sw / 2).to_i) and (sx + (sw / 2).to_i) < (x + w)) or
19991999 (sx < (x + (w / 2).to_i) and (x + (w / 2).to_i) < (sx + sw))
20002000 return
@@ -2818,10 +2818,10 @@ module Sakura
28182818 elsif chunk[1] == '%friendname'
28192819 buf << get_friendname()
28202820 elsif chunk[1] == '%screenwidth'
2821- left, top, scrn_w, scrn_h = @surface.get_workarea(@script_side)
2821+ left, top, scrn_w, scrn_h = get_workarea
28222822 buf << scrn_w.to_s
28232823 elsif chunk[1] == '%screenheight'
2824- left, top, scrn_w, scrn_h = @surface.get_workarea(@script_side)
2824+ left, top, scrn_w, scrn_h = get_workarea
28252825 buf << scrn_h.to_s
28262826 elsif chunk[1] == '%et'
28272827 buf << @current_time[5].to_s[-1] + '万年'
--- a/lib/ninix/surface.rb
+++ b/lib/ninix/surface.rb
@@ -595,7 +595,7 @@ module Surface
595595 end
596596
597597 def reset_position
598- left, top, scrn_w, scrn_h = get_workarea(0) # XXX
598+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
599599 s0x, s0y, s0w, s0h = 0, 0, 0, 0 # XXX
600600 for side in 0..@window.length-1
601601 align = get_alignment(side)
@@ -628,14 +628,6 @@ module Surface
628628 end
629629 end
630630
631- def get_workarea(side)
632- if @window.length > side
633- return @window[side].get_window.workarea
634- else
635- return [0, 0, 0, 0]
636- end
637- end
638-
639631 def set_position(side, x, y)
640632 if @window.length > side
641633 @window[side].set_position(x, y)
@@ -844,7 +836,7 @@ module Surface
844836 @mikire = @kasanari = 0
845837 return
846838 end
847- left, top, scrn_w, scrn_h = get_workarea(0)
839+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
848840 x0, y0 = get_position(0)
849841 s0w, s0h = get_surface_size(0)
850842 if (x0 + s0w / 3) < left or (x0 + s0w * 2 / 3) > (left + scrn_w) or \
@@ -976,7 +968,7 @@ module Surface
976968 return unless @side.zero?
977969 @reshape = true # XXX
978970 @parent.handle_request('NOTIFY', 'reset_position') # XXX
979- left, top, scrn_w, scrn_h = @window.workarea
971+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
980972 @parent.handle_request(
981973 'NOTIFY', 'notify_event', 'OnDisplayChange',
982974 Gdk.Visual.get_best_depth(), scrn_w, scrn_h)
@@ -1111,7 +1103,7 @@ module Surface
11111103 case get_alignment()
11121104 when 0
11131105 yoffset = (dh - h)
1114- left, top, scrn_w, scrn_h = @window.workarea
1106+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
11151107 y = (top + scrn_h - dh)
11161108 when 1
11171109 yoffset = 0
@@ -1391,7 +1383,7 @@ module Surface
13911383 end
13921384
13931385 def get_max_size
1394- left, top, scrn_w, scrn_h = @window.workarea
1386+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
13951387 w, h = @maxsize
13961388 scale = get_scale
13971389 w = [scrn_w, [8, (w * scale / 100).to_i].max].min
@@ -1469,7 +1461,7 @@ module Surface
14691461 @position = [x, y]
14701462 new_x, new_y = get_position()
14711463 @window.move(new_x, new_y)
1472- left, top, scrn_w, scrn_h = @window.workarea
1464+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
14731465 if x > (left + scrn_w / 2)
14741466 new_direction = 0
14751467 else
@@ -1506,13 +1498,13 @@ module Surface
15061498 return if @dragged # XXX: position will be reset after button release event
15071499 case align
15081500 when 0
1509- left, top, scrn_w, scrn_h = @window.workarea
1501+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
15101502 sw, sh = get_max_size()
15111503 sx, sy = @position # XXX: without window_offset
15121504 sy = (top + scrn_h - sh)
15131505 set_position(sx, sy)
15141506 when 1
1515- left, top, scrn_w, scrn_h = @window.workarea
1507+ left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea')
15161508 sx, sy = @position # XXX: without window_offset
15171509 sy = top
15181510 set_position(sx, sy)
--- a/lib/ninix_main.rb
+++ b/lib/ninix_main.rb
@@ -364,6 +364,7 @@ module Ninix_Main
364364 'reset_sstp_flag' => 'reset_sstp_flag',
365365 'get_sstp_port' => 'get_sstp_port',
366366 'get_prefix' => 'get_sakura_prefix',
367+ 'get_workarea' => 'get_workarea'
367368 }
368369 unless handlers.include?(event)
369370 if Application.method_defined?(event)
@@ -825,8 +826,9 @@ module Ninix_Main
825826 return nil
826827 end
827828
828- def run(abend)
829+ def run(abend, app_window)
829830 @abend = abend
831+ @app_window = app_window
830832 if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
831833 # The SIGTERM signal is not generated under Windows NT.
832834 # Win32::Console::API.SetConsoleCtrlHandler will probably not be implemented.
@@ -1258,6 +1260,10 @@ module Ninix_Main
12581260 end
12591261 return true
12601262 end
1263+
1264+ def get_workarea
1265+ [0, 0, *@app_window.size]
1266+ end
12611267 end
12621268
12631269 class Console
@@ -1687,15 +1693,20 @@ gtk_app.signal_connect 'activate' do |application|
16871693 rescue
16881694 raise SystemExit("ninix-aya is already running")
16891695 end
1696+ app_window = Pix::TransparentApplicationWindow.new(application)
1697+ app_window.set_title("Ninix-aya")
1698+ app_window.show_all
16901699 # start
16911700 app = Ninix_Main::Application.new(f, :sstp_port => sstp_port)
1692- app.run(abend)
1701+ app.run(abend, app_window)
1702+ # end
16931703 f.truncate(0)
16941704 begin
16951705 Lock.unlockfile(f)
16961706 rescue
16971707 #pass
16981708 end
1709+ app_window.destroy
16991710 end
17001711
17011712 begin
Show on old repository browser