Class: Win32::VirtualDesktop

Inherits:
Object
  • Object
show all
Defined in:
lib/Win32/VirtualDesktop.rb

Overview

A virtual desktop consists of a set of windows on it, a name, a numbered icon and whether it is active or not

Defined Under Namespace

Classes: SaveInfo, SetScreenName

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(virtual_desktops, up_icon_filename, down_icon_filename, icon_id, name, index, active, window_manager) ⇒ VirtualDesktop

Returns a new instance of VirtualDesktop.



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/Win32/VirtualDesktop.rb', line 89

def initialize(virtual_desktops, up_icon_filename, down_icon_filename, icon_id, name, index, active, window_manager)
	@virtual_desktops ||= virtual_desktops
	@up_icon ||= VRLocalScreen.factory.iconfromfile(up_icon_filename)
	@down_icon ||= VRLocalScreen.factory.iconfromfile(down_icon_filename)
	@icon_id ||= icon_id
	@name ||= name
	@index ||= index
	@windows ||= []
	@active ||= active
	@form ||= nil
	@windows ||= []
	@window_manager ||= window_manager
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



16
17
18
# File 'lib/Win32/VirtualDesktop.rb', line 16

def active
  @active
end

#formObject

Returns the value of attribute form.



17
18
19
# File 'lib/Win32/VirtualDesktop.rb', line 17

def form
  @form
end

#icon_idObject (readonly)

Returns the value of attribute icon_id.



15
16
17
# File 'lib/Win32/VirtualDesktop.rb', line 15

def icon_id
  @icon_id
end

#indexObject (readonly)

Returns the value of attribute index.



15
16
17
# File 'lib/Win32/VirtualDesktop.rb', line 15

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/Win32/VirtualDesktop.rb', line 15

def name
  @name
end

#windowsObject (readonly)

Returns the value of attribute windows.



15
16
17
# File 'lib/Win32/VirtualDesktop.rb', line 15

def windows
  @windows
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



84
85
86
# File 'lib/Win32/VirtualDesktop.rb', line 84

def create(*args)
	VirtualDesktop.new(*args)
end

Instance Method Details

#add_window(window) ⇒ Object



144
145
146
147
148
149
# File 'lib/Win32/VirtualDesktop.rb', line 144

def add_window(window)
	@virtual_desktops.add_window(window)
	@windows.push(window)
	$TRACE.debug 5, "adding window #{window}"
	$TRACE.debug 5, "after add windows = #{@windows.map{|w| w.to_s}.join(',')}"
end

#contains_window(window) ⇒ Object



171
172
173
# File 'lib/Win32/VirtualDesktop.rb', line 171

def contains_window(window)
	@windows.index(window)
end

#create_trayiconObject



115
116
117
# File 'lib/Win32/VirtualDesktop.rb', line 115

def create_trayicon
	form.create_trayicon(icon.hicon, @name, @icon_id)
end

#delete_trayiconObject



119
120
121
# File 'lib/Win32/VirtualDesktop.rb', line 119

def delete_trayicon
	form.delete_trayicon(@icon_id)
end

#handle_exitObject



157
158
159
# File 'lib/Win32/VirtualDesktop.rb', line 157

def handle_exit
	@windows.each {|window| window.show}
end

#iconObject



103
104
105
106
107
108
109
# File 'lib/Win32/VirtualDesktop.rb', line 103

def icon
	if @active then
		@down_icon
	else
		@up_icon
	end
end

#modify_trayiconObject



111
112
113
# File 'lib/Win32/VirtualDesktop.rb', line 111

def modify_trayicon
	form.modify_trayicon(icon.hicon, @name, @icon_id)	
end

#remove_window(window) ⇒ Object



151
152
153
154
155
# File 'lib/Win32/VirtualDesktop.rb', line 151

def remove_window(window)
	@windows.delete_if {|x| x.hwnd == window.hwnd}
	$TRACE.debug 5, "removing window #{window}"
	$TRACE.debug 5, "after remove windows = #{@windows.map{|w| w.to_s}.join(',')}"
end

#restore_info(save_info) ⇒ Object

when restoring those windows, find the window associated with the stored window handle and add it to the desktop and show it if we are active



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/Win32/VirtualDesktop.rb', line 200

def restore_info(save_info)
	window_handles = save_info.window_handles

	# add in the windows		
	$TRACE.debug 5, "window_handles = #{window_handles.inspect}"
	all_windows = @window_manager.get_all_windows(true).values
	$TRACE.debug 5, "all-windows = " + all_windows.map{|w| w.to_s}.join(",")
	window_handles.each do |hwnd|
		window = all_windows.select{|w| w.hwnd == hwnd}[0]
		if window then
			$TRACE.debug 5, "found window = #{window}"
			add_window(window)
			if @active then
				window.show
			else
				window.hide
			end
		end
	end

	# modify the tray icon name
	@name = save_info.name
	modify_trayicon
end

#save_infoObject

the info that we save for this desktop is just an array of window handles of the windows on this desktop



192
193
194
# File 'lib/Win32/VirtualDesktop.rb', line 192

def save_info
	SaveInfo.new(@windows.map{|w| w.hwnd}, @name)
end

#set_screen_nameObject



161
162
163
164
165
166
167
168
169
# File 'lib/Win32/VirtualDesktop.rb', line 161

def set_screen_name
	set_screen_name_form = VRLocalScreen.newdialog(@mainForm,nil,SetScreenName)
   	returnResult = set_screen_name_form.exinit(@name).open nil,true

   	if returnResult == VRDialogComponent::IDOK then
   		@name = set_screen_name_form.name
   		modify_trayicon
   	end
end

#to_sObject



175
176
177
# File 'lib/Win32/VirtualDesktop.rb', line 175

def to_s
	"#{name}: windows = " + @windows.map{|w| w.to_s}.join(",")		
end