Ruby GTK3移行後のメインリポジトリ
リビジョン | 08dd8a652153dd64901f150e289fe485aba87e79 (tree) |
---|---|
日時 | 2015-06-07 15:56:49 |
作者 | Shyouzou Sugitani <shy@user...> |
コミッター | Shyouzou Sugitani |
add dll/wmove.rb
@@ -0,0 +1,280 @@ | ||
1 | +# -*- coding: utf-8 -*- | |
2 | +# | |
3 | +# wmove.rb - a wmove.dll compatible Saori module for ninix | |
4 | +# Copyright (C) 2003-2015 by Shyouzou Sugitani <shy@users.osdn.me> | |
5 | +# | |
6 | +# This program is free software; you can redistribute it and/or modify it | |
7 | +# under the terms of the GNU General Public License (version 2) as | |
8 | +# published by the Free Software Foundation. It is distributed in the | |
9 | +# hope that it will be useful, but WITHOUT ANY WARRANTY; without even the | |
10 | +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
11 | +# PURPOSE. See the GNU General Public License for more details. | |
12 | +# | |
13 | + | |
14 | +# TODO: | |
15 | +# - STANDBY, STANDBY_INSIDE | |
16 | + | |
17 | + | |
18 | +require "gtk3" | |
19 | + | |
20 | +require "ninix/dll" | |
21 | +require "ninix/pix" | |
22 | + | |
23 | + | |
24 | +class Saori < DLL::SAORI | |
25 | + | |
26 | + def initialize | |
27 | + super() | |
28 | + @__sakura = nil | |
29 | + end | |
30 | + | |
31 | + def need_ghost_backdoor(sakura) | |
32 | + @__sakura = sakura | |
33 | + end | |
34 | + | |
35 | + def load(dir: nil) | |
36 | + @commands = [[], []] | |
37 | + @timeout_id = nil | |
38 | + @dir = dir | |
39 | + result = 0 | |
40 | + if not @__sakura | |
41 | + #pass | |
42 | + elsif @loaded == 1 | |
43 | + result = 2 | |
44 | + else | |
45 | + @sakura_name = @__sakura.get_selfname() | |
46 | + @kero_name = @__sakura.get_keroname() | |
47 | + @loaded = 1 | |
48 | + result = 1 | |
49 | + end | |
50 | + return result | |
51 | + end | |
52 | + | |
53 | + def finalize | |
54 | + if @timeout_id | |
55 | + GLib::Source.remove(@timeout_id) | |
56 | + @timeout_id = nil | |
57 | + end | |
58 | + @commands = [[], []] | |
59 | + @sakura_name = '' | |
60 | + @kero_name = '' | |
61 | + return 1 | |
62 | + end | |
63 | + | |
64 | + def __check_argument(argument) | |
65 | + name = argument[0] | |
66 | + result = true | |
67 | + list_hwnd = [@sakura_name, @kero_name] ## FIXME: HWND support | |
68 | + if ['MOVE', 'MOVE_INSIDE', 'MOVETO', 'MOVETO_INSIDE'].include?(name) | |
69 | + if argument.length != 4 or not list_hwnd.include?(argument[1]) | |
70 | + result = false | |
71 | + end | |
72 | + elsif ['ZMOVE', 'WAIT'].include?(name) | |
73 | + if argument.length != 3 or not list_hwnd.include?(argument[1]) | |
74 | + result = false | |
75 | + end | |
76 | + elsif ['STANDBY', 'STANDBY_INSIDE'].include?(name) | |
77 | + if argument.length != 6 or \ | |
78 | + not list_hwnd.include?(argument[1]) or \ | |
79 | + not list_hwnd.include?(argument[2]) | |
80 | + result = false | |
81 | + end | |
82 | + elsif ['GET_POSITION', 'CLEAR'].include?(name) | |
83 | + if argument.length != 2 or not list_hwnd.include?(argument[1]) | |
84 | + result = false | |
85 | + end | |
86 | + elsif name == 'GET_DESKTOP_SIZE' | |
87 | + if argument.length != 1 | |
88 | + result = false | |
89 | + end | |
90 | + elsif name == 'NOTIFY' | |
91 | + if argument.length < 3 or argument.length > 8 or \ | |
92 | + not list_hwnd.include?(argument[1]) | |
93 | + result = false | |
94 | + end | |
95 | + end | |
96 | + return result | |
97 | + end | |
98 | + | |
99 | + def request(req) | |
100 | + req_type, argument = evaluate_request(req) | |
101 | + if not req_type | |
102 | + result = RESPONSE[400] | |
103 | + elsif req_type == 'GET Version' | |
104 | + result = RESPONSE[204] | |
105 | + elsif req_type == 'EXECUTE' | |
106 | + result = execute(argument) | |
107 | + else | |
108 | + result = RESPONSE[400] | |
109 | + end | |
110 | + return result | |
111 | + end | |
112 | + | |
113 | + def execute(args) | |
114 | + if not args | |
115 | + result = RESPONSE[400] | |
116 | + elsif not __check_argument(args) | |
117 | + result = RESPONSE[400] | |
118 | + else | |
119 | + name = args[0] | |
120 | + if name == 'GET_POSITION' | |
121 | + if args[1] == @sakura_name ## FIXME: HWND support | |
122 | + side = 0 | |
123 | + elsif args[1] == @kero_name ## FIXME: HWND support | |
124 | + side = 1 | |
125 | + else | |
126 | + return RESPONSE[400] | |
127 | + end | |
128 | + begin | |
129 | + x, y = @__sakura.get_surface_position(side) | |
130 | + w, h = @__sakura.get_surface_size(side) | |
131 | + result = 'SAORI/1.0 200 OK\r\n' \ | |
132 | + 'Result: ' + x.to_s + '\r\n' \ | |
133 | + 'Value0: ' + x.to_s + '\r\n' \ | |
134 | + 'Value1: ' + (x + (w / 2).to_i).to_s + '\r\n' \ | |
135 | + 'Value2: ' + (x + w).to_s + '\r\n\r\n' | |
136 | + result = result.encode('ascii') | |
137 | + rescue | |
138 | + result = RESPONSE[500] | |
139 | + end | |
140 | + elsif name == 'GET_DESKTOP_SIZE' | |
141 | + begin | |
142 | + left, top, scrn_w, scrn_h = Pix.get_workarea() | |
143 | + result = 'SAORI/1.0 200 OK\r\n' \ | |
144 | + + 'Result: ' + scrn_w.to_s + '\r\n' \ | |
145 | + + 'Value0: ' + scrn_w.to_s + '\r\n' \ | |
146 | + + 'Value1: ' + scrn_h.to_s + '\r\n\r\n' | |
147 | + result = result.encode('ascii') | |
148 | + rescue | |
149 | + result = RESPONSE[500] | |
150 | + end | |
151 | + else | |
152 | + enqueue_commands(name, args[1..-1]) | |
153 | + if @timeout_id == nil | |
154 | + do_idle_tasks() | |
155 | + end | |
156 | + result = RESPONSE[204] | |
157 | + end | |
158 | + return result | |
159 | + end | |
160 | + end | |
161 | + | |
162 | + def enqueue_commands(command, args) | |
163 | + #assert ['MOVE', 'MOVE_INSIDE', 'MOVETO', 'MOVETO_INSIDE', | |
164 | + # 'ZMOVE', 'WAIT', 'NOTIFY', | |
165 | + # 'STANDBY', 'STANDBY_INSIDE', | |
166 | + # 'CLEAR'].include?(command) | |
167 | + if args[0] == @sakura_name ## FIXME: HWND support | |
168 | + side = 0 | |
169 | + elsif args[0] == @kero_name ## FIXME: HWND support | |
170 | + side = 1 | |
171 | + else | |
172 | + return # XXX | |
173 | + end | |
174 | + if command == 'CLEAR' | |
175 | + @commands[side] = [] | |
176 | + else | |
177 | + if ['STANDBY', 'STANDBY_INSIDE'].include?(command) | |
178 | + @commands[0] = [] | |
179 | + @commands[1] = [] | |
180 | + end | |
181 | + @commands[side] << [command, args[1..-1]] | |
182 | + end | |
183 | + end | |
184 | + | |
185 | + def do_idle_tasks | |
186 | + for side in [0, 1] | |
187 | + if @commands[side] | |
188 | + command, args = @commands[side].shift | |
189 | + if ['MOVE', 'MOVE_INSIDE'].include?(command) | |
190 | + x, y = @__sakura.get_surface_position(side) | |
191 | + vx = args[0].to_i | |
192 | + speed = args[1].to_i | |
193 | + if command == 'MOVE_INSIDE' | |
194 | + w, h = @__sakura.get_surface_size(side) | |
195 | + left, top, scrn_w, scrn_h = Pix.get_workarea() | |
196 | + if vx < 0 and x + vx <0 | |
197 | + vx = [-x, 0].min | |
198 | + elsif vx > 0 and x + vx + w > left + scrn_w | |
199 | + vx = [left + scrn_w - w - x, 0].max | |
200 | + end | |
201 | + end | |
202 | + if vx.abs > speed | |
203 | + if vx > 0 | |
204 | + @__sakura.set_surface_position( | |
205 | + side, x + speed, y) | |
206 | + @commands[side].insert( | |
207 | + 0, [command, [(vx - speed).to_s, args[1]]]) | |
208 | + elsif vx < 0 | |
209 | + @__sakura.set_surface_position( | |
210 | + side, x - speed, y) | |
211 | + @commands[side].insert( | |
212 | + 0, [command, [(vx + speed).to_s, args[1]]]) | |
213 | + end | |
214 | + else | |
215 | + @__sakura.set_surface_position(side, x + vx, y) | |
216 | + end | |
217 | + elsif ['MOVETO', 'MOVETO_INSIDE'].include?(command) | |
218 | + x, y = @__sakura.get_surface_position(side) | |
219 | + to = args[0].to_i | |
220 | + speed = args[1].to_i | |
221 | + if command == 'MOVETO_INSIDE' | |
222 | + w, h = @__sakura.get_surface_size(side) | |
223 | + left, top, scrn_w, scrn_h = Pix.get_workarea() | |
224 | + if to < 0 | |
225 | + to = 0 | |
226 | + elsif to > left + scrn_w - w | |
227 | + to = left + scrn_w - w | |
228 | + end | |
229 | + end | |
230 | + if (to - x).abs > speed | |
231 | + if to - x > 0 | |
232 | + @__sakura.set_surface_position( | |
233 | + side, x + speed, y) | |
234 | + @commands[side].insert(0, [command, args]) | |
235 | + elsif to - x < 0 | |
236 | + @__sakura.set_surface_position( | |
237 | + side, x - speed, y) | |
238 | + @commands[side].insert(0, [command, args]) | |
239 | + end | |
240 | + else | |
241 | + @__sakura.set_surface_position(side, to, y) | |
242 | + end | |
243 | + elsif ['STANDBY', 'STANDBY_INSIDE'].include?(command) | |
244 | + #pass ## FIXME | |
245 | + elsif command == 'ZMOVE' | |
246 | + if args[0] == '1' | |
247 | + @__sakura.raise_surface(side) | |
248 | + elsif args[0] == '2' | |
249 | + @__sakura.lower_surface(side) | |
250 | + else | |
251 | + #@pass | |
252 | + end | |
253 | + elsif command == 'WAIT' | |
254 | + begin | |
255 | + wait = args[0].to_i # ms | |
256 | + rescue | |
257 | + wait = 0 | |
258 | + end | |
259 | + if wait < 25 | |
260 | + #pass | |
261 | + else | |
262 | + @commands[side].insert(0, ['WAIT', (wait - 20).to_s]) | |
263 | + end | |
264 | + elsif command == 'NOTIFY' | |
265 | + @__sakura.notify_event(*args) | |
266 | + end | |
267 | + end | |
268 | + if not @commands[0] and not @commands[1] | |
269 | + if @timeout_id != nil | |
270 | + GLib::Source.remove(@timeout_id) | |
271 | + @timeout_id = nil | |
272 | + end | |
273 | + else | |
274 | + if @timeout_id == nil | |
275 | + @timeout_id = GLib::Timeout.add(20) { do_idle_tasks } | |
276 | + end | |
277 | + end | |
278 | + end | |
279 | + end | |
280 | +end |
@@ -0,0 +1,108 @@ | ||
1 | +require "ninix/dll/wmove" | |
2 | + | |
3 | +module NinixTest | |
4 | + | |
5 | + class WmoveTest | |
6 | + | |
7 | + def initialize | |
8 | + @x = [100, 320] | |
9 | + @y = [200, 400] | |
10 | + saori = Saori.new | |
11 | + saori.setup | |
12 | + saori.need_ghost_backdoor(self) | |
13 | + saori.load | |
14 | + saori.request("") # XXX | |
15 | + print(saori.execute(nil), "\n") | |
16 | + print(saori.execute(['GET_DESKTOP_SIZE']), "\n") | |
17 | + print(saori.execute(['GET_POSITION', ""]), "\n") | |
18 | + print(saori.execute(['GET_POSITION', get_selfname]), "\n") | |
19 | + print(saori.execute(['GET_POSITION', get_keroname]), "\n") | |
20 | + print(saori.execute(['CLEAR']), "\n") | |
21 | + print(saori.execute(['CLEAR', get_selfname]), "\n") | |
22 | + print(saori.execute(['CLEAR', get_keroname]), "\n") | |
23 | + print(saori.execute( | |
24 | + ['STANDBY', get_selfname, get_keroname, | |
25 | + "-10", "1", "5"]), | |
26 | + "\n") | |
27 | + print(saori.execute( | |
28 | + ['STANDBY_INSIDE', get_keroname, get_selfname, | |
29 | + "20", "3", "12"]), | |
30 | + "\n") | |
31 | + print(saori.execute(['MOVE', get_selfname, "100", "50"]), "\n") | |
32 | + print(saori.execute(['MOVE_INSIDE', get_keroname, "-100", "50"]), "\n") | |
33 | + saori.do_idle_tasks # move | |
34 | + saori.do_idle_tasks # move | |
35 | + saori.do_idle_tasks # move | |
36 | + print(saori.execute(['MOVETO', get_keroname, "640", "50"]), "\n") | |
37 | + print(saori.execute(['MOVETO_INSIDE', get_selfname, "320", "10"]), "\n") | |
38 | + saori.do_idle_tasks # moveto | |
39 | + saori.do_idle_tasks # moveto | |
40 | + saori.do_idle_tasks # moveto | |
41 | + saori.do_idle_tasks # moveto | |
42 | + saori.do_idle_tasks # moveto | |
43 | + saori.do_idle_tasks # moveto | |
44 | + saori.do_idle_tasks # moveto | |
45 | + saori.do_idle_tasks # moveto | |
46 | + saori.do_idle_tasks # moveto | |
47 | + saori.do_idle_tasks # moveto | |
48 | + saori.do_idle_tasks # moveto | |
49 | + saori.do_idle_tasks # moveto | |
50 | + saori.do_idle_tasks # moveto | |
51 | + print(saori.execute(['ZMOVE', get_selfname, '1']), "\n") | |
52 | + print(saori.execute(['ZMOVE', get_selfname, '2']), "\n") | |
53 | + print(saori.execute(['ZMOVE', get_keroname, '1']), "\n") | |
54 | + print(saori.execute(['ZMOVE', get_keroname, '2']), "\n") | |
55 | + saori.do_idle_tasks # raise | |
56 | + saori.do_idle_tasks # lower | |
57 | + print(saori.execute(['WAIT', get_selfname, "26"]), "\n") # > 25[ms] | |
58 | + print(saori.execute(['WAIT', get_keroname, "0"]), "\n") | |
59 | + saori.do_idle_tasks # wait | |
60 | + saori.do_idle_tasks # wait(only sakura side) | |
61 | + print(saori.execute( | |
62 | + ['NOTIFY', get_selfname, "TEST EVENT(S)", "REF0"]), | |
63 | + "\n") | |
64 | + print(saori.execute( | |
65 | + ['NOTIFY', get_keroname, "TEST EVENT(K)", "REF0", "REF1"]), | |
66 | + "\n") | |
67 | + saori.do_idle_tasks # notify | |
68 | + saori.finalize | |
69 | + end | |
70 | + | |
71 | + def get_selfname | |
72 | + return "Sakura" | |
73 | + end | |
74 | + | |
75 | + def get_keroname | |
76 | + return "Kero" | |
77 | + end | |
78 | + | |
79 | + def get_surface_size(side) | |
80 | + return 50, 100 | |
81 | + end | |
82 | + | |
83 | + def get_surface_position(side) | |
84 | + return @x[side], @y[side] | |
85 | + end | |
86 | + | |
87 | + def set_surface_position(side, x, y) | |
88 | + print("SIDE: ", side, "\n") | |
89 | + print("POSITION: ", x, ", ", y, "\n") | |
90 | + @x[side] = x | |
91 | + @y[side] = y | |
92 | + end | |
93 | + | |
94 | + def raise_surface(side) | |
95 | + print("RAISE: ", side, "\n") | |
96 | + end | |
97 | + | |
98 | + def lower_surface(side) | |
99 | + print("LOWER: ", side, "\n") | |
100 | + end | |
101 | + | |
102 | + def notify_event(*args) | |
103 | + print("NOTIFY: ", args, "\n") | |
104 | + end | |
105 | + end | |
106 | +end | |
107 | + | |
108 | +NinixTest::WmoveTest.new() |