Class: Win32::VirtualDesktops
- Inherits:
-
Array
- Object
- Array
- Win32::VirtualDesktops
- Defined in:
- lib/Win32/VirtualDesktop.rb
Overview
This class holds the array of virtual desktops
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- NUM_NAMES =
["one", "two", "three", "four", "five", "six", "seven", "eight"]
Instance Attribute Summary collapse
-
#active_desktop_index ⇒ Object
Returns the value of attribute active_desktop_index.
Class Method Summary collapse
-
.create(*args) ⇒ Object
create is here to allow another program to change how virtual desktops are created (use an object loaded off of disk instead of a freshly created one.
Instance Method Summary collapse
- #active_desktop ⇒ Object
- #add_window(window) ⇒ Object
- #change_desktop(icon_id) ⇒ Object
- #contains_window(window) ⇒ Object
- #create_trayicons ⇒ Object
- #delete_trayicons ⇒ Object
- #get_all_windows ⇒ Object
- #handle_exit ⇒ Object
-
#initialize(form, dir_base, icon_id_base, num_desktops, window_manager, *args) ⇒ VirtualDesktops
constructor
A new instance of VirtualDesktops.
- #move_window(icon_id) ⇒ Object
-
#periodic_timer ⇒ Object
this needs to be called periodically (< 1sec) to detect windows that are being closed or opened.
- #push(virtual_desktop) ⇒ Object
- #restore ⇒ Object
- #restore_info(virtual_desktop_infos) ⇒ Object
- #save ⇒ Object
- #save_info ⇒ Object
- #set_screen_name ⇒ Object
Constructor Details
#initialize(form, dir_base, icon_id_base, num_desktops, window_manager, *args) ⇒ VirtualDesktops
Returns a new instance of VirtualDesktops.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/Win32/VirtualDesktop.rb', line 242 def initialize(form, dir_base, icon_id_base, num_desktops, window_manager, *args) super(*args) @form ||= form @active_desktop_index ||= 0 @window_manager ||= window_manager @last_windows ||= get_all_windows @all_windows ||= [] NUM_NAMES.each_with_index do |number, index| icon_base = dir_base + "/" + number self.push(VirtualDesktop.create(self, icon_base + "_up.ico", icon_base + "_down.ico", icon_id_base+index, "Screen #{index+1}", index, index == 0, window_manager)) break if index+1 >= num_desktops end end |
Instance Attribute Details
#active_desktop_index ⇒ Object
Returns the value of attribute active_desktop_index.
230 231 232 |
# File 'lib/Win32/VirtualDesktop.rb', line 230 def active_desktop_index @active_desktop_index end |
Class Method Details
.create(*args) ⇒ Object
create is here to allow another program to change how virtual desktops are created (use an object loaded off of disk instead of a freshly created one
236 237 238 |
# File 'lib/Win32/VirtualDesktop.rb', line 236 def create(*args) VirtualDesktops.new(*args) end |
Instance Method Details
#active_desktop ⇒ Object
269 270 271 |
# File 'lib/Win32/VirtualDesktop.rb', line 269 def active_desktop self[@active_desktop_index] end |
#add_window(window) ⇒ Object
306 307 308 |
# File 'lib/Win32/VirtualDesktop.rb', line 306 def add_window(window) @all_windows.push(window) unless @all_windows.index(window) end |
#change_desktop(icon_id) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/Win32/VirtualDesktop.rb', line 273 def change_desktop(icon_id) clicked_desktop = self.select{|s| s.icon_id == icon_id}[0] $TRACE.debug 5, "change_desktop: #{icon_id} -> #{clicked_desktop} ? #{@active_desktop_index}" if clicked_desktop.index != @active_desktop_index then $TRACE.debug 5, "changing desktops" self.active_desktop_index = clicked_desktop.index # save the changed state save end end |
#contains_window(window) ⇒ Object
329 330 331 332 333 334 335 336 337 |
# File 'lib/Win32/VirtualDesktop.rb', line 329 def contains_window(window) self.each do |virtual_desktop| if virtual_desktop.contains_window(window) then return true end end return false end |
#create_trayicons ⇒ Object
310 311 312 313 314 |
# File 'lib/Win32/VirtualDesktop.rb', line 310 def create_trayicons self.reverse.each do |desktop| desktop.create_trayicon end end |
#delete_trayicons ⇒ Object
316 317 318 319 320 |
# File 'lib/Win32/VirtualDesktop.rb', line 316 def delete_trayicons self.each do |desktop| desktop.delete_trayicon end end |
#get_all_windows ⇒ Object
322 323 324 325 326 327 |
# File 'lib/Win32/VirtualDesktop.rb', line 322 def get_all_windows # select all non-tooltip windows @window_manager.get_all_windows.values.select do |w| !/tooltips/.match(w.class_name) end end |
#handle_exit ⇒ Object
411 412 413 414 415 |
# File 'lib/Win32/VirtualDesktop.rb', line 411 def handle_exit self.each do |desktop| desktop.handle_exit end end |
#move_window(icon_id) ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/Win32/VirtualDesktop.rb', line 285 def move_window(icon_id) # if the clicked desktop is not the active desktop then clicked_desktop = self.select{|s| s.icon_id == icon_id}[0] if clicked_desktop.index != @active_desktop_index then # get top window object windows = @window_manager.get_all_windows top_window_hwnd = @window_manager.get_top_window(windows) top_window = windows[top_window_hwnd] # move it from the active to the clicked desktop self[@active_desktop_index].remove_window(top_window) self[clicked_desktop.index].add_window(top_window) # and now hide it top_window.hide # save the changed state save end end |
#periodic_timer ⇒ Object
this needs to be called periodically (< 1sec) to detect windows that are being closed or opened
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/Win32/VirtualDesktop.rb', line 343 def periodic_timer current_windows = get_all_windows added_windows = current_windows - @last_windows removed_windows = @last_windows - current_windows $TRACE.debug 7, "cur windows = " + current_windows.map{|w|w.hwnd}.join(",") $TRACE.debug 7, "last windows = " + @last_windows.map{|w|w.hwnd}.join(",") $TRACE.debug 7, "added_windows = " + added_windows.map{|w|"#{w.hwnd}-#{w.class_name}"}.join(",") $TRACE.debug 7, "removed_windows = " + removed_windows.map{|w|"#{w.hwnd}-#{w.class_name}"}.join(",") active_desktop = self[@active_desktop_index] added_windows.each do |window| active_desktop.add_window(window) end removed_windows.each do |window| active_desktop.remove_window(window) end # save the state if there were any modifications if added_windows.size > 0 || removed_windows.size > 0 then save end @last_windows = current_windows end |
#push(virtual_desktop) ⇒ Object
257 258 259 260 |
# File 'lib/Win32/VirtualDesktop.rb', line 257 def push(virtual_desktop) super(virtual_desktop) virtual_desktop.form = @form end |
#restore ⇒ Object
402 403 404 405 406 407 408 409 |
# File 'lib/Win32/VirtualDesktop.rb', line 402 def restore configuration = nil File.open("c:/vtdesk.txt", "r") do |f| configuration = YAML::load(f) end restore_info(configuration.save_info) end |
#restore_info(virtual_desktop_infos) ⇒ Object
381 382 383 384 385 |
# File 'lib/Win32/VirtualDesktop.rb', line 381 def restore_info(virtual_desktop_infos) self.each_with_index do |virtual_desktop, i| virtual_desktop.restore_info(virtual_desktop_infos[i]) end end |
#save ⇒ Object
396 397 398 399 400 |
# File 'lib/Win32/VirtualDesktop.rb', line 396 def save File.open("c:/vtdesk.txt", "w") do |f| f.write(Configuration.new(self.save_info).to_yaml) end end |
#save_info ⇒ Object
373 374 375 376 377 378 379 |
# File 'lib/Win32/VirtualDesktop.rb', line 373 def save_info virtual_desktops = [] self.each do |vd| virtual_desktops.push(vd.save_info) end virtual_desktops end |
#set_screen_name ⇒ Object
369 370 371 |
# File 'lib/Win32/VirtualDesktop.rb', line 369 def set_screen_name self[@active_desktop_index].set_screen_name end |