|
1 // screenmode.cpp |
|
2 // |
|
3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include <fshell/common.mmh> |
|
14 |
|
15 #if defined (FSHELL_PLATFORM_S60) && FSHELL_PLATFORM_S60 >= 5 |
|
16 #include "AknCapServerClient.h" //for screen orientation change |
|
17 #endif |
|
18 |
|
19 #include <W32STD.H> |
|
20 |
|
21 #include <fshell/ioutils.h> |
|
22 using namespace IoUtils; |
|
23 |
|
24 class CCmdScreenMode : public CCommandBase |
|
25 { |
|
26 public: |
|
27 void PrintTime(const TTime& aTime, TBool aNewline); |
|
28 static const TDesC* EventCodeToString(TUint aEvent); |
|
29 static const TDesC* DisplayModeToString(TDisplayMode aMode); |
|
30 static const TDesC* RotationToString(CFbsBitGc::TGraphicsOrientation aRotation); |
|
31 static const TDesC* EnforcementToString(TScreenModeEnforcement aEnforcement); |
|
32 static CCommandBase* NewLC(); |
|
33 ~CCmdScreenMode(); |
|
34 private: |
|
35 CCmdScreenMode(); |
|
36 void PrintCurrentModeDetailL(); |
|
37 void DoListModeL(); |
|
38 void DoSetModeL(); |
|
39 void DoFollowL(); |
|
40 void DoRotateL(); |
|
41 |
|
42 private: // From CCommandBase. |
|
43 virtual const TDesC& Name() const; |
|
44 virtual void DoRunL(); |
|
45 virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
46 virtual void OptionsL(RCommandOptionList& aOptions); |
|
47 |
|
48 private: |
|
49 RWsSession iWsSes; |
|
50 CWsScreenDevice* iWsDev; |
|
51 |
|
52 TBool iVerbose; |
|
53 TInt iOptModeIndex; // Which mode to use. |
|
54 |
|
55 enum TScreenModeCmd |
|
56 { |
|
57 ECmdListMode, |
|
58 ECmdSetMode, |
|
59 ECmdFollow, |
|
60 ECmdRotate |
|
61 }; |
|
62 |
|
63 TScreenModeCmd iCommand; |
|
64 }; |
|
65 |
|
66 CCommandBase* CCmdScreenMode::NewLC() |
|
67 { |
|
68 CCmdScreenMode* self = new(ELeave) CCmdScreenMode(); |
|
69 CleanupStack::PushL(self); |
|
70 self->BaseConstructL(); |
|
71 return self; |
|
72 } |
|
73 |
|
74 CCmdScreenMode::CCmdScreenMode() |
|
75 { |
|
76 } |
|
77 |
|
78 CCmdScreenMode::~CCmdScreenMode() |
|
79 { |
|
80 delete iWsDev; |
|
81 iWsDev = NULL; |
|
82 iWsSes.Close(); |
|
83 } |
|
84 |
|
85 const TDesC& CCmdScreenMode::Name() const |
|
86 { |
|
87 _LIT(KName, "screenmode"); |
|
88 return KName; |
|
89 } |
|
90 |
|
91 void CCmdScreenMode::ArgumentsL(RCommandArgumentList& aArguments) |
|
92 { |
|
93 _LIT(KArgCommand, "command"); |
|
94 aArguments.AppendEnumL((TInt&)iCommand, KArgCommand); |
|
95 } |
|
96 |
|
97 void CCmdScreenMode::OptionsL(RCommandOptionList& aOptions) |
|
98 { |
|
99 aOptions.AppendBoolL(iVerbose, _L("verbose")); |
|
100 aOptions.AppendUintL((TUint&)iOptModeIndex, _L("mode")); |
|
101 } |
|
102 |
|
103 void CCmdScreenMode::PrintCurrentModeDetailL() |
|
104 { |
|
105 TInt scrMode = iWsDev->CurrentScreenMode(); |
|
106 TPixelsTwipsAndRotation modeSizeAndRotation; |
|
107 iWsDev->GetDefaultScreenSizeAndRotation(modeSizeAndRotation); |
|
108 const TDesC* pRotationStr = RotationToString(modeSizeAndRotation.iRotation); |
|
109 |
|
110 TPoint origin = iWsDev->GetDefaultScreenModeOrigin(); |
|
111 TSize scale = iWsDev->GetCurrentScreenModeScale(); |
|
112 TPoint scaledOrigin = iWsDev->GetCurrentScreenModeScaledOrigin(); |
|
113 TScreenModeEnforcement screenModeEnforcement = iWsDev->ScreenModeEnforcement(); |
|
114 const TDesC* pEnforcementStr = EnforcementToString(screenModeEnforcement); |
|
115 |
|
116 Printf(_L("Current ScreenMode %d,%dx%d,Twips:%dx%d,%S\r\n"), scrMode, |
|
117 modeSizeAndRotation.iPixelSize.iWidth, modeSizeAndRotation.iPixelSize.iHeight, |
|
118 modeSizeAndRotation.iTwipsSize.iWidth , modeSizeAndRotation.iTwipsSize.iHeight, |
|
119 pRotationStr); |
|
120 Printf(_L("Origin:(%d,%d) Scale:%dx%d ScaledOrigin:(%d,%d) %S\r\n"), |
|
121 origin.iX, origin.iX, scale.iWidth, scale.iHeight, scaledOrigin.iX, scaledOrigin.iY, |
|
122 pEnforcementStr); |
|
123 } |
|
124 |
|
125 //if VerboseLevel > 0, then print every message received |
|
126 // |
|
127 void CCmdScreenMode::DoFollowL() |
|
128 { |
|
129 const TUint KClientHandle = 0xC0C0C0C0; |
|
130 TInt err; |
|
131 //TInt verboseLevel = iVerbose.Count(); |
|
132 |
|
133 RWindowGroup wndGrp(iWsSes); |
|
134 err = wndGrp.Construct(KClientHandle); |
|
135 LeaveIfErr(err, _L("Could not construct window group")); |
|
136 |
|
137 CleanupClosePushL(wndGrp); |
|
138 err = wndGrp.EnableScreenChangeEvents(); |
|
139 LeaveIfErr(err, _L("Could not enable screen change events")); |
|
140 |
|
141 Printf(_L("Tracking screen change events... press 'q' to quit\r\n")); |
|
142 |
|
143 TWsEvent event; |
|
144 TInt eventType; |
|
145 TUint eventHandle; |
|
146 TTime eventTime; |
|
147 TRequestStatus status; |
|
148 |
|
149 RIoConsoleReadHandle& keyIn = Stdin(); |
|
150 TRequestStatus statusKey; |
|
151 keyIn.WaitForKey(statusKey); |
|
152 |
|
153 for(;;) |
|
154 { |
|
155 iWsSes.EventReady(&status); |
|
156 WaitAgain: |
|
157 User::WaitForRequest(status, statusKey); |
|
158 |
|
159 if (status.Int()==KRequestPending) |
|
160 { |
|
161 err = statusKey.Int(); |
|
162 ASSERT(err == KErrNone); |
|
163 //it must be user press a key, so check if that key is 'q' |
|
164 TUint pressedKey = keyIn.KeyCode(); |
|
165 if (pressedKey=='q' || pressedKey=='Q') |
|
166 break; |
|
167 else |
|
168 { |
|
169 keyIn.WaitForKey(statusKey); |
|
170 goto WaitAgain; |
|
171 } |
|
172 } |
|
173 |
|
174 iWsSes.GetEvent(event); |
|
175 |
|
176 eventType = event.Type(); |
|
177 eventHandle = event.Handle(); |
|
178 eventTime = event.Time(); |
|
179 |
|
180 /* |
|
181 if (verboseLevel > 0) |
|
182 { |
|
183 const TDesC* eventCodeStr = EventCodeToString(eventType); |
|
184 Printf(_L(" Event:%d(%S) Handle:0x%08x Time:"), eventType, eventCodeStr, |
|
185 eventHandle); |
|
186 PrintTime(eventTime, ETrue); |
|
187 } |
|
188 */ |
|
189 |
|
190 if (eventType == EEventScreenDeviceChanged && eventHandle==KClientHandle) |
|
191 { |
|
192 // Get the new screen mode and size |
|
193 TInt newMode = iWsDev->CurrentScreenMode(); |
|
194 TPixelsTwipsAndRotation modeSizeAndRotation; |
|
195 iWsDev->GetScreenModeSizeAndRotation(newMode, modeSizeAndRotation); |
|
196 |
|
197 Printf(_L("\r\n")); |
|
198 Printf(_L("Screen Device Changed, EventTime:")); |
|
199 PrintTime(eventTime, ETrue); |
|
200 PrintCurrentModeDetailL(); |
|
201 } |
|
202 } |
|
203 |
|
204 wndGrp.DisableScreenChangeEvents(); |
|
205 CleanupStack::PopAndDestroy(&wndGrp); |
|
206 } |
|
207 |
|
208 //S60 proprietary: toggle screen oritation by calling CAknCapServer::RotateScreenL |
|
209 // |
|
210 void CCmdScreenMode::DoRotateL() |
|
211 { |
|
212 #if defined (FSHELL_PLATFORM_S60) && FSHELL_PLATFORM_S60 >= 5 |
|
213 TInt err; |
|
214 RAknUiServer akSrv; |
|
215 err = akSrv.Connect(); |
|
216 LeaveIfErr(err, _L("Could not connect to AknCapServer")); |
|
217 |
|
218 CleanupClosePushL(akSrv); |
|
219 |
|
220 if (iVerbose) |
|
221 { |
|
222 Printf(_L("Calling RAknUiServer::RotateScreen() / CAknCapServer::RotateScreenL...\r\n")); |
|
223 } |
|
224 err = akSrv.RotateScreen(); |
|
225 LeaveIfErr(err, _L("RotateScreen() failed")); |
|
226 |
|
227 CleanupStack::PopAndDestroy(&akSrv); |
|
228 if (iVerbose) |
|
229 { |
|
230 PrintCurrentModeDetailL(); |
|
231 } |
|
232 #else |
|
233 LeaveIfErr(KErrNotSupported, _L("Rotate not supported on this platform.")); |
|
234 #endif |
|
235 } |
|
236 |
|
237 void CCmdScreenMode::DoSetModeL() |
|
238 { |
|
239 TInt numScreenModes = iWsDev->NumScreenModes(); |
|
240 if ( (iOptModeIndex >= numScreenModes) || iOptModeIndex<0) |
|
241 { |
|
242 LeaveIfErr(KErrArgument, _L("Invalid screenmode index:%d"), iOptModeIndex); |
|
243 } |
|
244 |
|
245 if (iVerbose) |
|
246 { |
|
247 Printf(_L("Calling CWsScreenDevice::SetScreenMode(%d)\r\n"), iOptModeIndex); |
|
248 } |
|
249 iWsDev->SetScreenMode(iOptModeIndex); |
|
250 |
|
251 //verify the result by query current screen mode |
|
252 if (iVerbose) |
|
253 { |
|
254 PrintCurrentModeDetailL(); |
|
255 } |
|
256 } |
|
257 |
|
258 void CCmdScreenMode::DoListModeL() |
|
259 { |
|
260 //for platform defined with SYMBIAN_WSERV_AND_CONE_MULTIPLE_SCREENS |
|
261 //it would be possible to query how many screens on this device |
|
262 //but S60 5.0 doesn't define this |
|
263 //TInt Screens = iWsSes.NumberOfScreens(); |
|
264 TInt curScreenNum = iWsDev->GetScreenNumber(); |
|
265 TInt numScreenModes = iWsDev->NumScreenModes(); |
|
266 Printf(_L("Current Screen number:%d Screen Modes:%d \r\n"), curScreenNum, numScreenModes); |
|
267 |
|
268 for (TInt i=0; i<numScreenModes; i++) |
|
269 { |
|
270 Printf(_L("-------------------------------------------\r\n")); |
|
271 TDisplayMode dMode = iWsDev->GetScreenModeDisplayMode(i); |
|
272 const TDesC* pModeString = DisplayModeToString(dMode); |
|
273 TSize modeScale = iWsDev->GetScreenModeScale(i); |
|
274 TPoint modeOrigin = iWsDev->GetScreenModeOrigin(i); |
|
275 TPoint scaledOrigin = iWsDev->GetScreenModeScaledOrigin(i); |
|
276 |
|
277 TPixelsTwipsAndRotation modeSizeAndRotation; |
|
278 iWsDev->GetScreenModeSizeAndRotation(i, modeSizeAndRotation); |
|
279 const TDesC* pRotationStr = RotationToString(modeSizeAndRotation.iRotation); |
|
280 |
|
281 Printf(_L("Mode:%d DisplayMode:%S Scale(WxH):%dx%d Origin:(%d,%d) ScaledOrigin:(%d,%d)\r\n"), |
|
282 i, pModeString, |
|
283 modeScale.iWidth, modeScale.iHeight, |
|
284 modeOrigin.iX, modeOrigin.iY, scaledOrigin.iX, scaledOrigin.iY); |
|
285 |
|
286 Printf(_L("Size(WxH) Pixels:%dx%d, Twips:%dx%d %S\r\n"), |
|
287 modeSizeAndRotation.iPixelSize.iWidth, modeSizeAndRotation.iPixelSize.iHeight, |
|
288 modeSizeAndRotation.iTwipsSize.iWidth, modeSizeAndRotation.iTwipsSize.iHeight, |
|
289 pRotationStr); |
|
290 } |
|
291 |
|
292 //current screen mode |
|
293 Printf(_L("===========================================\r\n")); |
|
294 PrintCurrentModeDetailL(); |
|
295 } |
|
296 |
|
297 void CCmdScreenMode::DoRunL() |
|
298 { |
|
299 TInt err; |
|
300 err = iWsSes.Connect(); |
|
301 LeaveIfErr(err, _L("Could not connect to the window server")); |
|
302 |
|
303 iWsDev = new (ELeave) CWsScreenDevice(iWsSes); |
|
304 err = iWsDev->Construct(); |
|
305 LeaveIfErr(err, _L("Could not construct CWsScreenDevice")); |
|
306 |
|
307 switch(iCommand) |
|
308 { |
|
309 case ECmdListMode: |
|
310 DoListModeL(); |
|
311 break; |
|
312 case ECmdSetMode: |
|
313 DoSetModeL(); |
|
314 break; |
|
315 case ECmdFollow: |
|
316 DoFollowL(); |
|
317 break; |
|
318 case ECmdRotate: |
|
319 DoRotateL(); |
|
320 break; |
|
321 } |
|
322 |
|
323 } |
|
324 |
|
325 EXE_BOILER_PLATE(CCmdScreenMode) |
|
326 |
|
327 #define CASE_MODELIT(x) case x: { _LIT(KName, #x); pString = &KName; break; } |
|
328 |
|
329 const TDesC* CCmdScreenMode::DisplayModeToString(TDisplayMode aMode) |
|
330 { |
|
331 enum { EColor16MAP = EColor16MA+1 }; // Not defined in 9.1 |
|
332 const TDesC* pString = NULL; |
|
333 switch(aMode) |
|
334 { |
|
335 CASE_MODELIT(ENone); |
|
336 CASE_MODELIT(EGray2); |
|
337 CASE_MODELIT(EGray4); |
|
338 CASE_MODELIT(EGray16); |
|
339 CASE_MODELIT(EGray256); |
|
340 CASE_MODELIT(EColor16); |
|
341 CASE_MODELIT(EColor256); |
|
342 CASE_MODELIT(EColor64K); |
|
343 CASE_MODELIT(EColor16M); |
|
344 CASE_MODELIT(ERgb); |
|
345 CASE_MODELIT(EColor4K); |
|
346 CASE_MODELIT(EColor16MU); |
|
347 CASE_MODELIT(EColor16MA); |
|
348 CASE_MODELIT(EColor16MAP); |
|
349 default: |
|
350 _LIT(KUnknowStr, "Unknown"); |
|
351 pString = &KUnknowStr; |
|
352 } |
|
353 return pString; |
|
354 } |
|
355 |
|
356 const TDesC* CCmdScreenMode::EnforcementToString(TScreenModeEnforcement aEnforcement) |
|
357 { |
|
358 const TDesC* pString = NULL; |
|
359 switch(aEnforcement) |
|
360 { |
|
361 CASE_MODELIT(ESizeEnforcementNone); |
|
362 CASE_MODELIT(ESizeEnforcementPixelsAndRotation); |
|
363 CASE_MODELIT(ESizeEnforcementPixelsTwipsAndRotation); |
|
364 default: |
|
365 _LIT(KUnknowStr, "Unknown"); |
|
366 pString = &KUnknowStr; |
|
367 } |
|
368 return pString; |
|
369 } |
|
370 |
|
371 const TDesC* CCmdScreenMode::EventCodeToString(TUint aEvent) |
|
372 { |
|
373 const TDesC* pString = NULL; |
|
374 switch(aEvent) |
|
375 { |
|
376 CASE_MODELIT(EEventNull); |
|
377 CASE_MODELIT(EEventKey); |
|
378 CASE_MODELIT(EEventKeyUp); |
|
379 CASE_MODELIT(EEventKeyDown); |
|
380 CASE_MODELIT(EEventModifiersChanged); |
|
381 CASE_MODELIT(EEventPointer); |
|
382 CASE_MODELIT(EEventPointerEnter); |
|
383 CASE_MODELIT(EEventPointerExit); |
|
384 CASE_MODELIT(EEventPointerBufferReady); |
|
385 CASE_MODELIT(EEventDragDrop); |
|
386 CASE_MODELIT(EEventFocusLost); |
|
387 CASE_MODELIT(EEventFocusGained); |
|
388 CASE_MODELIT(EEventSwitchOn); |
|
389 CASE_MODELIT(EEventPassword); |
|
390 CASE_MODELIT(EEventWindowGroupsChanged); |
|
391 CASE_MODELIT(EEventErrorMessage); |
|
392 CASE_MODELIT(EEventMessageReady); |
|
393 CASE_MODELIT(EEventMarkInvalid); |
|
394 CASE_MODELIT(EEventSwitchOff); |
|
395 CASE_MODELIT(EEventKeySwitchOff); |
|
396 CASE_MODELIT(EEventScreenDeviceChanged); |
|
397 CASE_MODELIT(EEventFocusGroupChanged); |
|
398 CASE_MODELIT(EEventCaseOpened); |
|
399 CASE_MODELIT(EEventCaseClosed); |
|
400 CASE_MODELIT(EEventWindowGroupListChanged); |
|
401 CASE_MODELIT(EEventWindowVisibilityChanged); |
|
402 #ifdef SYMBIAN_PROCESS_MONITORING_AND_STARTUP |
|
403 CASE_MODELIT(EEventRestartSystem); |
|
404 #endif |
|
405 CASE_MODELIT(EEventKeyRepeat); |
|
406 |
|
407 //the following 3 are not defined in S60 3.2 |
|
408 #if defined (FSHELL_PLATFORM_S60) && FSHELL_PLATFORM_S60 >= 5 |
|
409 CASE_MODELIT(EEventGroupWindowOpen); |
|
410 CASE_MODELIT(EEventGroupWindowClose); |
|
411 CASE_MODELIT(EEventWindowClose); |
|
412 #endif |
|
413 |
|
414 CASE_MODELIT(EEventDirectScreenAccessBegin); |
|
415 CASE_MODELIT(EEventDirectScreenAccessEnd); |
|
416 CASE_MODELIT(EEventHeartbeatTimerStateChange); |
|
417 CASE_MODELIT(EEventPowerMgmt); |
|
418 CASE_MODELIT(EEventReserved); |
|
419 CASE_MODELIT(EEventUser); |
|
420 default: |
|
421 _LIT(KUnknowStr, "Unknown"); |
|
422 pString = &KUnknowStr; |
|
423 } |
|
424 return pString; |
|
425 } |
|
426 |
|
427 #define CASE_ROTLIT(x) case CFbsBitGc::x: { _LIT(KName, #x); pString = &KName; break; } |
|
428 |
|
429 const TDesC* CCmdScreenMode::RotationToString(CFbsBitGc::TGraphicsOrientation aRotation) |
|
430 { |
|
431 const TDesC* pString = NULL; |
|
432 switch(aRotation) |
|
433 { |
|
434 CASE_ROTLIT(EGraphicsOrientationNormal); |
|
435 CASE_ROTLIT(EGraphicsOrientationRotated90); |
|
436 CASE_ROTLIT(EGraphicsOrientationRotated180); |
|
437 CASE_ROTLIT(EGraphicsOrientationRotated270); |
|
438 default: |
|
439 _LIT(KUnknowStr, "Unknown"); |
|
440 pString = &KUnknowStr; |
|
441 } |
|
442 return pString; |
|
443 } |
|
444 |
|
445 void CCmdScreenMode::PrintTime(const TTime& aTime, TBool aNewline) |
|
446 { |
|
447 TTime NullTime = Time::NullTTime(); |
|
448 if (aTime == NullTime) |
|
449 { |
|
450 Printf(_L("(NullTime)")); |
|
451 } |
|
452 else |
|
453 { |
|
454 _LIT8(KDateTimeFormat, "%d-%02d-%02d %02d:%02d:%02d"); |
|
455 TDateTime dt = aTime.DateTime(); |
|
456 Printf(KDateTimeFormat, dt.Year(), dt.Month()+1, dt.Day()+1, dt.Hour(), dt.Minute(), dt.Second()); |
|
457 } |
|
458 |
|
459 if (aNewline) |
|
460 { |
|
461 Printf(_L("\r\n")); |
|
462 } |
|
463 } |