Ruby GTK3移行後のメインリポジトリ
リビジョン | 57dc26d0b131baddc3b57fb4b723c3dba63ec32a (tree) |
---|---|
日時 | 2019-01-06 22:22:58 |
作者 | Shyouzou Sugitani <shy@user...> |
コミッター | Shyouzou Sugitani |
introduce Gtk::ApplicationWindow
@@ -1,4 +1,5 @@ | ||
1 | 1 | Sun January 6 2019 Shyouzou Sugitani <shy@users.osdn.me> |
2 | + * Gtk::ApplicationWindowを生成し、画面サイズ算出に利用するようにした. | |
2 | 3 | * Gtk::Applicationを使用するようにした. |
3 | 4 | * AYA, AYA5互換モジュールにおいてFixnum(deprecated)を |
4 | 5 | 使用しないよう修正した. |
@@ -798,7 +798,7 @@ module Balloon | ||
798 | 798 | x = (base_x + px) |
799 | 799 | end |
800 | 800 | 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') | |
802 | 802 | if (y + h) > scrn_h # XXX |
803 | 803 | y = (scrn_h - h) |
804 | 804 | end |
@@ -1537,7 +1537,7 @@ module Balloon | ||
1537 | 1537 | Gtk::StateFlags::NORMAL, Gdk::RGBA.new(0, 0, 0, 0)) |
1538 | 1538 | w = desc.get('communicatebox.width', :default => 250).to_i |
1539 | 1539 | 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') | |
1541 | 1541 | @__surface_position = [(scrn_w - w) / 2, (scrn_h - h) / 2] # XXX |
1542 | 1542 | @entry = Gtk::Entry.new |
1543 | 1543 | @entry.signal_connect('activate') do |w| |
@@ -210,7 +210,7 @@ module Bln | ||
210 | 210 | else |
211 | 211 | @position = 'sakura' |
212 | 212 | end |
213 | - left, top, scrn_w, scrn_h = @window.workarea | |
213 | + left, top, scrn_w, scrn_h = @__sakura.get_workarea | |
214 | 214 | # -1: left, 1: right |
215 | 215 | if @position == 'sakura' |
216 | 216 | s0_x, s0_y, s0_w, s0_h = get_sakura_status('SurfaceSakura') |
@@ -501,7 +501,7 @@ module Bln | ||
501 | 501 | end |
502 | 502 | |
503 | 503 | def get_coordinate(w, h) |
504 | - left, top, scrn_w, scrn_h = @window.workarea | |
504 | + left, top, scrn_w, scrn_h = @__sakura.get_workarea | |
505 | 505 | s0_x, s0_y, s0_w, s0_h = get_sakura_status('SurfaceSakura') |
506 | 506 | s1_x, s1_y, s1_w, s1_h = get_sakura_status('SurfaceKero') |
507 | 507 | b0_x, b0_y, b0_w, b0_h = get_sakura_status('BalloonSakura') |
@@ -103,7 +103,7 @@ module Osuwari | ||
103 | 103 | def do_idle_tasks |
104 | 104 | return false if @timeout_id.nil? |
105 | 105 | 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 | |
107 | 107 | target_flag = [false, false] |
108 | 108 | if target == 'ACTIVE' |
109 | 109 | active_window = get_active_window() |
@@ -142,7 +142,7 @@ module Wmove | ||
142 | 142 | end |
143 | 143 | elsif name == 'GET_DESKTOP_SIZE' |
144 | 144 | begin |
145 | - left, top, scrn_w, scrn_h = @__sakura.get_workarea(0) # XXX | |
145 | + left, top, scrn_w, scrn_h = @__sakura.get_workarea | |
146 | 146 | result = ("SAORI/1.0 200 OK\r\n" \ |
147 | 147 | + "Result: " + scrn_w.to_s + "\r\n" \ |
148 | 148 | + "Value0: " + scrn_w.to_s + "\r\n" \ |
@@ -194,7 +194,7 @@ module Wmove | ||
194 | 194 | speed = args[1].to_i |
195 | 195 | if command == 'MOVE_INSIDE' |
196 | 196 | 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 | |
198 | 198 | if vx < 0 and x + vx <0 |
199 | 199 | vx = [-x, 0].min |
200 | 200 | elsif vx > 0 and x + vx + w > left + scrn_w |
@@ -222,7 +222,7 @@ module Wmove | ||
222 | 222 | speed = args[1].to_i |
223 | 223 | if command == 'MOVETO_INSIDE' |
224 | 224 | 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 | |
226 | 226 | if to < 0 |
227 | 227 | to = 0 |
228 | 228 | elsif to > left + scrn_w - w |
@@ -150,6 +150,7 @@ module Nekodorif | ||
150 | 150 | scale = @target.get_surface_scale() |
151 | 151 | @skin = Skin.new(@dir, @accelgroup, scale) |
152 | 152 | @skin.set_responsible(self) |
153 | + @skin.setup | |
153 | 154 | return 0 if @skin.nil? |
154 | 155 | @katochan_list = katochan |
155 | 156 | @katochan = nil |
@@ -164,6 +165,7 @@ module Nekodorif | ||
164 | 165 | handlers = { |
165 | 166 | 'get_katochan_list' => lambda { return @katochan_list }, |
166 | 167 | 'get_mode' => lambda { return @mode }, |
168 | + 'get_workarea' => lambda { return @target.get_workarea }, | |
167 | 169 | } |
168 | 170 | if handlers.include?(event) |
169 | 171 | result = handlers[event].call # no argument |
@@ -302,9 +304,6 @@ module Nekodorif | ||
302 | 304 | next true |
303 | 305 | end |
304 | 306 | @id = [0, nil] |
305 | - set_surface() | |
306 | - set_position(:reset => 1) | |
307 | - @window.show_all() | |
308 | 307 | end |
309 | 308 | |
310 | 309 | def set_responsible(parent) |
@@ -327,6 +326,12 @@ module Nekodorif | ||
327 | 326 | return result if event_type == 'GET' |
328 | 327 | end |
329 | 328 | |
329 | + def setup | |
330 | + set_surface() | |
331 | + set_position(:reset => 1) | |
332 | + @window.show_all() | |
333 | + end | |
334 | + | |
330 | 335 | def set_scale(scale) |
331 | 336 | @__scale = scale |
332 | 337 | set_surface() |
@@ -402,7 +407,7 @@ module Nekodorif | ||
402 | 407 | end |
403 | 408 | |
404 | 409 | 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') | |
406 | 411 | unless reset.zero? |
407 | 412 | @x = left |
408 | 413 | @y = (top + scrn_h - @h) |
@@ -621,7 +626,7 @@ module Nekodorif | ||
621 | 626 | return if @settings['state'] != 'before' |
622 | 627 | target_x, target_y = @target.get_surface_position(@side) |
623 | 628 | 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') | |
625 | 630 | @x = (target_x + target_w / 2 - @w / 2 + (@offset_x * @__scale / 100).to_i) |
626 | 631 | @y = (top + (@offset_y * @__scale / 100).to_i) |
627 | 632 | @window.move(@x, @y) |
@@ -782,7 +787,7 @@ module Nekodorif | ||
782 | 787 | end |
783 | 788 | |
784 | 789 | 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') | |
786 | 791 | if (@x + @w - @w / 3) > (left + scrn_w) or \ |
787 | 792 | (@x + @w / 3) < left or \ |
788 | 793 | (@y + @h - @h / 3) > (top + scrn_h) or \ |
@@ -83,7 +83,7 @@ module Pix | ||
83 | 83 | |
84 | 84 | class BaseTransparentWindow < Gtk::Window |
85 | 85 | alias :base_move :move |
86 | - attr_reader :workarea, :supports_alpha | |
86 | + attr_reader :supports_alpha | |
87 | 87 | |
88 | 88 | def initialize(type: Gtk::WindowType::TOPLEVEL) |
89 | 89 | super(type) |
@@ -105,12 +105,6 @@ module Pix | ||
105 | 105 | end |
106 | 106 | @supports_alpha = composited? |
107 | 107 | 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] | |
114 | 108 | maximize # not fullscreen |
115 | 109 | end |
116 | 110 | end |
@@ -200,6 +194,36 @@ module Pix | ||
200 | 194 | end |
201 | 195 | |
202 | 196 | |
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 | + | |
203 | 227 | def self.get_png_size(path) |
204 | 228 | return 0, 0 if not File.exists?(path) |
205 | 229 | buf = |
@@ -577,8 +577,8 @@ module Sakura | ||
577 | 577 | @balloon.reset_balloon() |
578 | 578 | end |
579 | 579 | |
580 | - def get_workarea(side) | |
581 | - @surface.get_workarea(side) | |
580 | + def get_workarea | |
581 | + @parent.handle_request('GET', 'get_workarea') | |
582 | 582 | end |
583 | 583 | |
584 | 584 | def get_surface_position(side) |
@@ -867,7 +867,7 @@ module Sakura | ||
867 | 867 | :default => default) |
868 | 868 | end |
869 | 869 | end |
870 | - left, top, scrn_w, scrn_h = @surface.get_workarea(0) # XXX | |
870 | + left, top, scrn_w, scrn_h = get_workarea | |
871 | 871 | notify_event('OnDisplayChange', |
872 | 872 | Gdk::Visual.best_depth, |
873 | 873 | scrn_w, scrn_h, :event_type => 'NOTIFY') |
@@ -1964,7 +1964,7 @@ module Sakura | ||
1964 | 1964 | end |
1965 | 1965 | w, h = get_surface_size(@script_side) |
1966 | 1966 | 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 | |
1968 | 1968 | if (sx + (sw / 2).to_i) > (left + (scrn_w / 2).to_i) |
1969 | 1969 | new_x = [x - (scrn_w / 20).to_i, sx - (scrn_w / 20).to_i].min |
1970 | 1970 | else |
@@ -1994,7 +1994,7 @@ module Sakura | ||
1994 | 1994 | end |
1995 | 1995 | w, h = get_surface_size(@script_side) |
1996 | 1996 | 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 | |
1998 | 1998 | if (x < (sx + (sw / 2).to_i) and (sx + (sw / 2).to_i) < (x + w)) or |
1999 | 1999 | (sx < (x + (w / 2).to_i) and (x + (w / 2).to_i) < (sx + sw)) |
2000 | 2000 | return |
@@ -2818,10 +2818,10 @@ module Sakura | ||
2818 | 2818 | elsif chunk[1] == '%friendname' |
2819 | 2819 | buf << get_friendname() |
2820 | 2820 | 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 | |
2822 | 2822 | buf << scrn_w.to_s |
2823 | 2823 | 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 | |
2825 | 2825 | buf << scrn_h.to_s |
2826 | 2826 | elsif chunk[1] == '%et' |
2827 | 2827 | buf << @current_time[5].to_s[-1] + '万年' |
@@ -595,7 +595,7 @@ module Surface | ||
595 | 595 | end |
596 | 596 | |
597 | 597 | 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') | |
599 | 599 | s0x, s0y, s0w, s0h = 0, 0, 0, 0 # XXX |
600 | 600 | for side in 0..@window.length-1 |
601 | 601 | align = get_alignment(side) |
@@ -628,14 +628,6 @@ module Surface | ||
628 | 628 | end |
629 | 629 | end |
630 | 630 | |
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 | - | |
639 | 631 | def set_position(side, x, y) |
640 | 632 | if @window.length > side |
641 | 633 | @window[side].set_position(x, y) |
@@ -844,7 +836,7 @@ module Surface | ||
844 | 836 | @mikire = @kasanari = 0 |
845 | 837 | return |
846 | 838 | end |
847 | - left, top, scrn_w, scrn_h = get_workarea(0) | |
839 | + left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea') | |
848 | 840 | x0, y0 = get_position(0) |
849 | 841 | s0w, s0h = get_surface_size(0) |
850 | 842 | if (x0 + s0w / 3) < left or (x0 + s0w * 2 / 3) > (left + scrn_w) or \ |
@@ -976,7 +968,7 @@ module Surface | ||
976 | 968 | return unless @side.zero? |
977 | 969 | @reshape = true # XXX |
978 | 970 | @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') | |
980 | 972 | @parent.handle_request( |
981 | 973 | 'NOTIFY', 'notify_event', 'OnDisplayChange', |
982 | 974 | Gdk.Visual.get_best_depth(), scrn_w, scrn_h) |
@@ -1111,7 +1103,7 @@ module Surface | ||
1111 | 1103 | case get_alignment() |
1112 | 1104 | when 0 |
1113 | 1105 | 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') | |
1115 | 1107 | y = (top + scrn_h - dh) |
1116 | 1108 | when 1 |
1117 | 1109 | yoffset = 0 |
@@ -1391,7 +1383,7 @@ module Surface | ||
1391 | 1383 | end |
1392 | 1384 | |
1393 | 1385 | 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') | |
1395 | 1387 | w, h = @maxsize |
1396 | 1388 | scale = get_scale |
1397 | 1389 | w = [scrn_w, [8, (w * scale / 100).to_i].max].min |
@@ -1469,7 +1461,7 @@ module Surface | ||
1469 | 1461 | @position = [x, y] |
1470 | 1462 | new_x, new_y = get_position() |
1471 | 1463 | @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') | |
1473 | 1465 | if x > (left + scrn_w / 2) |
1474 | 1466 | new_direction = 0 |
1475 | 1467 | else |
@@ -1506,13 +1498,13 @@ module Surface | ||
1506 | 1498 | return if @dragged # XXX: position will be reset after button release event |
1507 | 1499 | case align |
1508 | 1500 | when 0 |
1509 | - left, top, scrn_w, scrn_h = @window.workarea | |
1501 | + left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea') | |
1510 | 1502 | sw, sh = get_max_size() |
1511 | 1503 | sx, sy = @position # XXX: without window_offset |
1512 | 1504 | sy = (top + scrn_h - sh) |
1513 | 1505 | set_position(sx, sy) |
1514 | 1506 | when 1 |
1515 | - left, top, scrn_w, scrn_h = @window.workarea | |
1507 | + left, top, scrn_w, scrn_h = @parent.handle_request('GET', 'get_workarea') | |
1516 | 1508 | sx, sy = @position # XXX: without window_offset |
1517 | 1509 | sy = top |
1518 | 1510 | set_position(sx, sy) |
@@ -364,6 +364,7 @@ module Ninix_Main | ||
364 | 364 | 'reset_sstp_flag' => 'reset_sstp_flag', |
365 | 365 | 'get_sstp_port' => 'get_sstp_port', |
366 | 366 | 'get_prefix' => 'get_sakura_prefix', |
367 | + 'get_workarea' => 'get_workarea' | |
367 | 368 | } |
368 | 369 | unless handlers.include?(event) |
369 | 370 | if Application.method_defined?(event) |
@@ -825,8 +826,9 @@ module Ninix_Main | ||
825 | 826 | return nil |
826 | 827 | end |
827 | 828 | |
828 | - def run(abend) | |
829 | + def run(abend, app_window) | |
829 | 830 | @abend = abend |
831 | + @app_window = app_window | |
830 | 832 | if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ |
831 | 833 | # The SIGTERM signal is not generated under Windows NT. |
832 | 834 | # Win32::Console::API.SetConsoleCtrlHandler will probably not be implemented. |
@@ -1258,6 +1260,10 @@ module Ninix_Main | ||
1258 | 1260 | end |
1259 | 1261 | return true |
1260 | 1262 | end |
1263 | + | |
1264 | + def get_workarea | |
1265 | + [0, 0, *@app_window.size] | |
1266 | + end | |
1261 | 1267 | end |
1262 | 1268 | |
1263 | 1269 | class Console |
@@ -1687,15 +1693,20 @@ gtk_app.signal_connect 'activate' do |application| | ||
1687 | 1693 | rescue |
1688 | 1694 | raise SystemExit("ninix-aya is already running") |
1689 | 1695 | end |
1696 | + app_window = Pix::TransparentApplicationWindow.new(application) | |
1697 | + app_window.set_title("Ninix-aya") | |
1698 | + app_window.show_all | |
1690 | 1699 | # start |
1691 | 1700 | app = Ninix_Main::Application.new(f, :sstp_port => sstp_port) |
1692 | - app.run(abend) | |
1701 | + app.run(abend, app_window) | |
1702 | + # end | |
1693 | 1703 | f.truncate(0) |
1694 | 1704 | begin |
1695 | 1705 | Lock.unlockfile(f) |
1696 | 1706 | rescue |
1697 | 1707 | #pass |
1698 | 1708 | end |
1709 | + app_window.destroy | |
1699 | 1710 | end |
1700 | 1711 | |
1701 | 1712 | begin |