Merge lp://qastaging/~alexlauni/do-plugins/xrandr into lp://qastaging/~johannes-rudolph/do-plugins/xrandr-plugin

Proposed by Alex Launi
Status: Merged
Merged at revision: not available
Proposed branch: lp://qastaging/~alexlauni/do-plugins/xrandr
Merge into: lp://qastaging/~johannes-rudolph/do-plugins/xrandr-plugin
Diff against target: None lines
To merge this branch: bzr merge lp://qastaging/~alexlauni/do-plugins/xrandr
Reviewer Review Type Date Requested Status
Do Plugins Team Pending
Review via email: mp+8399@code.qastaging.launchpad.net
To post a comment you must log in.
Revision history for this message
Alex Launi (alexlauni) wrote :

You still had lot of formatting issues, I've fixed them and have a final question - why have you defined AccessorImpl<T> as a public class inside of Tools?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Firefox/src/PlacesItemSource.cs'
2--- Firefox/src/PlacesItemSource.cs 2009-06-22 04:05:16 +0000
3+++ Firefox/src/PlacesItemSource.cs 2009-06-29 22:41:20 +0000
4@@ -120,8 +120,9 @@
5
6 public override void UpdateItems ()
7 {
8- places = LoadPlaceItems ();
9- folders = LoadFolderItems ();
10+ // evaluate immediate to allow sql connections to close
11+ places = LoadPlaceItems ().ToArray ();
12+ folders = LoadFolderItems ().ToArray ();
13
14 items.Clear();
15
16@@ -300,6 +301,7 @@
17 }
18 }
19 }
20+ dbcon.Close ();
21 }
22 }
23 }
24
25=== modified file 'OpenSearch/src/OpenSearchParser.cs'
26--- OpenSearch/src/OpenSearchParser.cs 2009-01-18 18:40:54 +0000
27+++ OpenSearch/src/OpenSearchParser.cs 2009-06-29 23:24:59 +0000
28@@ -82,10 +82,10 @@
29 templateUrl += node.Attributes["name"].Value + "=" + node.Attributes["value"].Value + "&";
30 }
31
32- templateUrl = templateUrl.TrimEnd (new char [] {'&','?'});
33+ templateUrl = templateUrl.TrimEnd (new [] {'&', '?'});
34 }
35
36- return new OpenSearchItem (shortName.InnerText, "OpenSearch plugin: " + description.InnerText, templateUrl);
37+ return new OpenSearchItem (shortName.InnerText, description.InnerText, templateUrl);
38 }
39
40 /// <summary>
41
42=== modified file 'SSH/src/SSHHostItemSource.cs'
43--- SSH/src/SSHHostItemSource.cs 2009-06-22 04:05:16 +0000
44+++ SSH/src/SSHHostItemSource.cs 2009-07-02 18:44:25 +0000
45@@ -65,24 +65,24 @@
46 try {
47 string home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
48 string hostsFile = Path.Combine(home, ".ssh/config");
49- FileStream fs = new FileStream (hostsFile, FileMode.Open, FileAccess.Read);
50-
51- Regex NameRegex = new Regex ("^\\s*Host\\s+(.+)\\s*$");
52-
53- using (StreamReader reader = new StreamReader (fs))
54- {
55- string s;
56- while ((s = reader.ReadLine ()) != null) {
57- Match NameMatch = NameRegex.Match (s);
58- if (NameMatch.Groups.Count != 2) continue;
59-
60- string line = NameMatch.Groups[1].ToString();
61- string[] hosts = line.Split(new string[] { " " }, StringSplitOptions.None);
62- foreach (string host in hosts)
63- items.Add (new SSHHostItem (host));
64+
65+ using (FileStream fs = new FileStream (hostsFile, FileMode.Open, FileAccess.Read)) {
66+ Regex NameRegex = new Regex ("^\\s*Host\\s+(.+)\\s*$");
67+
68+ using (StreamReader reader = new StreamReader (fs))
69+ {
70+ string s;
71+ while ((s = reader.ReadLine ()) != null) {
72+ Match NameMatch = NameRegex.Match (s);
73+ if (NameMatch.Groups.Count != 2) continue;
74+
75+ string line = NameMatch.Groups[1].ToString();
76+ string[] hosts = line.Split(new string[] { " " }, StringSplitOptions.None);
77+ foreach (string host in hosts)
78+ items.Add (new SSHHostItem (host));
79+ }
80 }
81 }
82- fs.Dispose ();
83 } catch { }
84 }
85 }
86
87=== modified file 'XRandR/src/OutputModeItem.cs'
88--- XRandR/src/OutputModeItem.cs 2009-06-28 13:49:23 +0000
89+++ XRandR/src/OutputModeItem.cs 2009-07-08 15:43:17 +0000
90@@ -27,19 +27,19 @@
91
92 namespace XRandR
93 {
94- public class OutputModeItem:Item,IRunnableItem
95+ public class OutputModeItem : Item,IRunnableItem
96 {
97 string name;
98 int output_id, mode_id;
99
100- public OutputModeItem(int output_id, XRRModeInfo mode)
101+ public OutputModeItem (int output_id, XRRModeInfo mode)
102 {
103 this.output_id = output_id;
104 this.mode_id = mode.id.ToInt32 ();
105 this.name = mode.name + " " + mode.dotClock.ToInt64 () / mode.vTotal / mode.hTotal + "Hz";
106 }
107
108- public OutputModeItem(int output_id, int mode_id, string name)
109+ public OutputModeItem (int output_id, int mode_id, string name)
110 {
111 this.name = name;
112 this.mode_id = mode_id;
113
114=== modified file 'XRandR/src/XRandRItemSource.cs'
115--- XRandR/src/XRandRItemSource.cs 2009-06-28 13:49:23 +0000
116+++ XRandR/src/XRandRItemSource.cs 2009-07-08 15:43:17 +0000
117@@ -64,7 +64,7 @@
118 if (parent is OutputItem) {
119 OutputItem outputItem = parent as OutputItem;
120 foreach(ScreenResources res in Wrapper.ScreenResources ()) {
121- foreach(XRROutputInfo output in res.Outputs.DoWith (outputItem.Id)){
122+ foreach(XRROutputInfo output in res.Outputs.DoWith (outputItem.Id)) {
123 foreach(XRRModeInfo mode in res.ModesOfOutput (output)) {
124 yield return new OutputModeItem (outputItem.Id, mode);
125 }
126@@ -83,10 +83,13 @@
127 try {
128 items.Clear ();
129 foreach (ScreenResources res in Wrapper.ScreenResources ()){
130- res.Outputs.AllWithId (delegate (int id, XRROutputInfo output){
131- Do.Platform.Log<XRandRItemSource>.Debug ("Found output: 0x{0:x} - {1}", id, output.name);
132- items.Add (new OutputItem (id, output, output.connection == 0));
133- });
134+ res.Outputs.AllWithId (
135+ delegate (int id, XRROutputInfo output)
136+ {
137+ Do.Platform.Log<XRandRItemSource>.Debug ("Found output: 0x{0:x} - {1}", id, output.name);
138+ items.Add (new OutputItem (id, output, output.connection == 0));
139+ }
140+ );
141 }
142 } catch (Exception e) {
143 // Necessary, since Do.Universe.SafeElement.LogSafeError does not output a StackTrace
144
145=== modified file 'XRandR/src/XRandRWrapper.cs'
146--- XRandR/src/XRandRWrapper.cs 2009-06-28 13:55:48 +0000
147+++ XRandR/src/XRandRWrapper.cs 2009-07-08 15:43:17 +0000
148@@ -34,31 +34,37 @@
149 {
150 public static T Structure<T> (IntPtr ptr)
151 {
152- return (T) Marshal.PtrToStructure (ptr, typeof(T));
153+ return (T) Marshal.PtrToStructure (ptr, typeof (T));
154 }
155
156- public interface Accessor<T> {
157+ public interface Accessor<T>
158+ {
159 void DoWith (int id, ResourceAction<T> func);
160 IEnumerable<T> DoWith (int id);
161 void AllWithId(ResourceActionWithId<T> func);
162- IEnumerable<T> All{get;}
163- IEnumerable<int> Ids{get;}
164+ IEnumerable<T> All { get; }
165+ IEnumerable<int> Ids { get; }
166 }
167+
168 public delegate IntPtr RetrieveFunc (int id);
169+
170 public delegate void FreeFunc (IntPtr element);
171- public class AccessorImpl<T> : Accessor<T>{
172+
173+ public class AccessorImpl<T> : Accessor<T>
174+ {
175+ private FreeFunc freeF;
176 private RetrieveFunc getF;
177- private FreeFunc freeF;
178 private IEnumerable<int> ids;
179+
180 public AccessorImpl (RetrieveFunc getF, FreeFunc freeF, IEnumerable<int> ids)
181 {
182+ this.ids = ids;
183 this.getF = getF;
184 this.freeF = freeF;
185- this.ids = ids;
186 }
187
188 public IEnumerable<T> All {
189- get{
190+ get {
191 foreach(int id in ids){
192 IntPtr ptr = getF (id);
193 yield return Structure<T> (ptr);
194@@ -66,6 +72,7 @@
195 }
196 }
197 }
198+
199 public void AllWithId (ResourceActionWithId<T> func)
200 {
201 foreach(int id in ids) {
202@@ -74,20 +81,23 @@
203 freeF (ptr);
204 }
205 }
206- public void DoWith(int id, ResourceAction<T> func)
207+
208+ public void DoWith (int id, ResourceAction<T> func)
209 {
210 IntPtr ptr = getF (id);
211 func (Structure<T> (ptr));
212 freeF (ptr);
213 }
214+
215 public IEnumerable<T> DoWith (int id)
216 {
217 IntPtr ptr = getF (id);
218 yield return Structure<T> (ptr);
219 freeF (ptr);
220 }
221- public IEnumerable<int> Ids{
222- get{
223+
224+ public IEnumerable<int> Ids {
225+ get {
226 return ids;
227 }
228 }
229@@ -96,29 +106,32 @@
230 // some helper to access different sorts of unmanaged arrays
231
232 // defined as int * in a structure
233- public static int[] PtrToIntArray(IntPtr ptr, int numElements)
234+ public static int [] PtrToIntArray(IntPtr ptr, int numElements)
235 {
236- int[] res = new int[numElements];
237- for (int i=0;i<numElements;i++)
238- res[i] = Marshal.ReadIntPtr (ptr, IntPtr.Size * i).ToInt32 ();
239+ int [] res = new int [numElements];
240+ for (int i = 0; i < numElements; i++)
241+ res [i] = Marshal.ReadIntPtr (ptr, IntPtr.Size * i).ToInt32 ();
242 return res;
243 }
244+
245 // defined as struct** in a structure
246- public static T[] PtrToStructurePtrArray<T> (IntPtr ptr, int numElements)
247+ public static T [] PtrToStructurePtrArray<T> (IntPtr ptr, int numElements)
248 {
249- T[] res = new T[numElements];
250+ T [] res = new T[numElements];
251 for (int i=0;i<numElements;i++){
252- res[i] = (T) Marshal.PtrToStructure (Marshal.ReadIntPtr (ptr, IntPtr.Size * i), (Type)typeof(T));
253+ res [i] = (T) Marshal.PtrToStructure (Marshal.ReadIntPtr (ptr, IntPtr.Size * i), (Type) typeof(T));
254 }
255 return res;
256 }
257+
258 // defined as struct* in a structure
259- public static T[] PtrToStructureArray<T>(IntPtr ptr,int numElements)
260+ public static T [] PtrToStructureArray<T> (IntPtr ptr,int numElements)
261 {
262- T[] res = new T[numElements];
263- for (int i=0;i<numElements;i++)
264- res[i] = (T) Marshal.PtrToStructure (new IntPtr (ptr.ToInt64 () + i * Marshal.SizeOf (typeof(T)))
265- ,typeof(T));
266+ T [] res = new T [numElements];
267+ for (int i = 0; i < numElements; i++) {
268+ IntPtr ptr = new IntPtr (ptr.ToInt64 () + i * Marshal.SizeOf (typeof (T)));
269+ res [i] = (T) Marshal.PtrToStructure (typeof (T), typeof (T));
270+ }
271 return res;
272 }
273
274@@ -132,20 +145,27 @@
275 Do.Platform.Log<XRandR.Tools>.Debug ("\t{0} (+ {2}) = {1}", fi.Name, fi.GetValue(o), Marshal.OffsetOf (t,fi.Name));
276 }
277
278- public class XErrorException:Exception
279+ public class XErrorException : Exception
280 {
281+ string error_text;
282 XErrorEvent xevent;
283- string error_text;
284- internal XErrorException(XErrorEvent xevent, string text){
285+
286+ internal XErrorException (XErrorEvent xevent, string text)
287+ {
288 this.xevent = xevent;
289 this.error_text = text;
290 }
291- public override string ToString() {
292- return "got X error: "+"display:"+xevent.display+
293- " error:"+((int)xevent.error_code)+"("+error_text+")"+
294- " serial:"+xevent.serial+
295- " request:"+xevent.request_code+
296- " minor:"+xevent.minor_code;
297+
298+ public override string ToString ()
299+ {
300+ string.Format ("got X error: display: {0} error: {1} ({2}) serial: {3} request: {4} minor: {5}",
301+ xevent.display,
302+ (int)xevent.error_code,
303+ error_text,
304+ xevent.serial,
305+ xevent.request_code,
306+ xevent.minor_code
307+ );
308 }
309 }
310
311@@ -155,6 +175,7 @@
312 Native.XGetErrorText (display, xevent.error_code, sb, sb.Capacity);
313 return sb.ToString ();
314 }
315+
316 public static IntPtr IgnoreErrorHandler (IntPtr display, IntPtr ev)
317 {
318 XErrorEvent xevent = Structure<XErrorEvent> (ev);
319@@ -168,6 +189,7 @@
320 throw excp;
321 }
322 }
323+
324 public class Wrapper
325 {
326 public static void DoWithDefaultDisplay (ResourceAction<IntPtr> func)
327@@ -175,25 +197,30 @@
328 foreach(IntPtr display in DefaultDisplay ())
329 func(display);
330 }
331+
332 // IEnumerable wrapper around resource, makes sure resources are freed after usage.
333 // It is the reponsibility of the user to don't leak any pointers outside of the foreach block.
334 public static IEnumerable<IntPtr> DefaultDisplay()
335 {
336 IntPtr oldHandler = Native.XSetErrorHandler (Marshal.GetFunctionPointerForDelegate (new Native.ErrorHandler (Tools.IgnoreErrorHandler)));
337 IntPtr display = Native.XOpenDisplay (null);
338- try{
339+
340+ try {
341 yield return display;
342 }
343- finally{
344+
345+ finally {
346 Native.XCloseDisplay (display);
347 Native.XSetErrorHandler (oldHandler);
348 }
349 }
350+
351 public static void DoWithScreenResources (IntPtr display, ResourceAction<ScreenResources> func)
352 {
353- foreach(ScreenResources res in ScreenResources (display))
354+ foreach (ScreenResources res in ScreenResources (display))
355 func(res);
356 }
357+
358 public static IEnumerable<ScreenResources> ScreenResources (IntPtr display)
359 {
360 IntPtr w = Native.XRootWindow (display, 0);
361@@ -201,63 +228,70 @@
362 yield return new ScreenResources (display, res);
363 Native.XRRFreeScreenResources (res);
364 }
365+
366 public static void DoWithScreenResources (ResourceAction<ScreenResources> func)
367 {
368 DoWithDefaultDisplay (delegate (IntPtr display){DoWithScreenResources (display, func);});
369 }
370- public static IEnumerable<ScreenResources> ScreenResources()
371+
372+ public static IEnumerable<ScreenResources> ScreenResources ()
373 {
374 foreach(IntPtr display in DefaultDisplay ())
375 foreach(ScreenResources res in ScreenResources (display))
376 yield return res;
377 }
378 }
379- public class ScreenResources {
380+
381+ public class ScreenResources
382+ {
383 IntPtr display;
384 IntPtr presources;
385 XRRScreenResources resources;
386- Dictionary<int,XRRModeInfo> modes = new Dictionary<int,XRRModeInfo>();
387+ Dictionary<int,XRRModeInfo> modes = new Dictionary<int,XRRModeInfo> ();
388
389- internal ScreenResources(IntPtr d, IntPtr presources)
390+ internal ScreenResources (IntPtr d, IntPtr presources)
391 {
392 this.resources = Tools.Structure<XRRScreenResources> (presources);
393 Tools.LogStructure (this.resources);
394 this.presources = presources;
395 this.display = d;
396
397- foreach(XRRModeInfo mode in Tools.PtrToStructureArray<XRRModeInfo>(resources.modes,resources.nmode)){
398- modes[mode.id.ToInt32()] = mode;
399+ foreach (XRRModeInfo mode in Tools.PtrToStructureArray<XRRModeInfo> (resources.modes,resources.nmode)) {
400+ modes [mode.id.ToInt32 ()] = mode;
401 }
402 }
403
404 public Tools.Accessor<XRROutputInfo> Outputs {
405- get{
406- return new Tools.AccessorImpl<XRROutputInfo> (delegate (int id) {
407- return Native.XRRGetOutputInfo (display, presources,id);
408- }
409- ,Native.XRRFreeOutputInfo
410- ,Tools.PtrToIntArray (resources.outputs, resources.noutput));
411+ get {
412+ return new Tools.AccessorImpl<XRROutputInfo> (
413+ delegate (int id) {
414+ return Native.XRRGetOutputInfo (display, presources,id);
415+ }, Native.XRRFreeOutputInfo, Tools.PtrToIntArray (resources.outputs, resources.noutput)
416+ );
417 }
418 }
419+
420 public Tools.Accessor<XRRCrtcInfo> Crtcs {
421- get{
422- return new Tools.AccessorImpl<XRRCrtcInfo> (delegate (int id) {
423- return Native.XRRGetCrtcInfo (display, presources, id);
424- }
425- ,Native.XRRFreeCrtcInfo
426- ,Tools.PtrToIntArray (resources.crtcs, resources.ncrtc));
427+ get {
428+ return new Tools.AccessorImpl<XRRCrtcInfo> (
429+ delegate (int id) {
430+ return Native.XRRGetCrtcInfo (display, presources, id);
431+ }, Native.XRRFreeCrtcInfo, Tools.PtrToIntArray (resources.crtcs, resources.ncrtc)
432+ );
433 }
434 }
435
436- public XRRModeInfo GetMode(int id)
437+ public XRRModeInfo GetMode (int id)
438 {
439 return modes[id];
440 }
441- public IEnumerable<XRRModeInfo> Modes()
442+
443+ public IEnumerable<XRRModeInfo> Modes ()
444 {
445 return modes.Values;
446 }
447- public IEnumerable<XRRModeInfo> ModesOfOutput(XRROutputInfo output)
448+
449+ public IEnumerable<XRRModeInfo> ModesOfOutput (XRROutputInfo output)
450 {
451 foreach(int mode_id in Tools.PtrToIntArray (output.modes, output.nmode))
452 yield return GetMode (mode_id);
453@@ -269,24 +303,25 @@
454 }
455 }
456
457- public static void SafeSetConfig (IntPtr display, IntPtr res, IntPtr crtc_id, IntPtr timestamp, int x, int y, IntPtr mode_id, int rotation, int[] outputs)
458+ public static void SafeSetConfig (IntPtr display, IntPtr res, IntPtr crtc_id, IntPtr timestamp, int x, int y,
459+ IntPtr mode_id, int rotation, int [] outputs)
460 {
461- try{
462- IntPtr ptr = Marshal.AllocHGlobal (sizeof(int) * outputs.Length);
463- for(int i=0;i<outputs.Length;i++)
464- Marshal.WriteInt32 (ptr, sizeof(int)*i, outputs[i]);
465+ try {
466+ IntPtr ptr = Marshal.AllocHGlobal (sizeof (int) * outputs.Length);
467+ for (int i = 0; i < outputs.Length; i++)
468+ Marshal.WriteInt32 (ptr, sizeof (int) * i, outputs [i]);
469+
470 Native.XRRSetCrtcConfig (display, res, crtc_id, timestamp, x, y, mode_id, rotation, ptr, outputs.Length);
471 Marshal.FreeHGlobal (ptr);
472- }
473- catch(Tools.XErrorException excp){
474+ } catch (Tools.XErrorException excp) {
475 Do.Platform.Log<XRandR.Tools>.Debug ("Error when calling XRRSetCtrcConfig: 0x{0:x},{1},{2},{3},0x{4:x},{5},[{6}]"
476- ,crtc_id
477- ,timestamp
478- ,x
479- ,y
480- ,mode_id
481- ,rotation
482- ,outputs);
483+ ,crtc_id
484+ ,timestamp
485+ ,x
486+ ,y
487+ ,mode_id
488+ ,rotation
489+ ,outputs);
490 throw excp;
491 }
492 }
493@@ -302,19 +337,6 @@
494 Do.Platform.Log<XRandR.Tools>.Debug ("Setting mode using: '{0}'", cmd);
495
496 System.Diagnostics.Process.Start (cmd);
497- /*foreach(XRROutputInfo output in Outputs.doWith(output_id)){
498- int crtc_id = output.crtc_id;
499-
500- if (mode_id != 0){
501- if (crtc_id == 0) // if output is switched off, output has no crtc defined, so we use 1st one
502- crtc_id = Tools.PtrToIntArray(output.crtcs,output.ncrtc)[0];
503-
504- foreach(XRRCrtcInfo crtc in Crtcs.doWith(crtc_id))
505- safeSetConfig(display,presources,crtc_id,0,crtc.x,crtc.y,mode_id,crtc.rotation,new[]{output_id});
506- }
507- else // switch off output, by setting the mode of the crtc of the output to 0
508- safeSetConfig(display,presources,crtc_id,output.timestamp,0,0,0,1,new int[0]);
509- }*/
510 }
511 }
512
513@@ -323,18 +345,20 @@
514 {
515 public static void PrintModeInfo (XRRModeInfo mode)
516 {
517- Console.WriteLine ("Id: "+mode.id+" Name: "+mode.name+" width: "+mode.width+" height: "+mode.height);
518- }
519- public static void PrintOutputInfo (int id,XRROutputInfo output)
520+ Console.WriteLine ("Id: {0} Name: {1} Width: {2} Height {3}", mode.id, mode.name, mode.width, mode.height);
521+ }
522+
523+ public static void PrintOutputInfo (int id, XRROutputInfo output)
524 {
525 Console.WriteLine ("Id: {0} Name: {1} Connection: {2} crtc:{3}", id, output.name, output.connection, output.crtc_id);
526 }
527- public static void Main(string[] args)
528+
529+ public static void Main (string [] args)
530 {
531- Tools.LogStructure (new XRRScreenResources());
532- Tools.LogStructure (new XRRCrtcInfo());
533- Tools.LogStructure (new XRRModeInfo());
534- Tools.LogStructure (new XRROutputInfo());
535+ Tools.LogStructure (new XRRScreenResources ());
536+ Tools.LogStructure (new XRRCrtcInfo ());
537+ Tools.LogStructure (new XRRModeInfo ());
538+ Tools.LogStructure (new XRROutputInfo ());
539 }
540 }
541 }

Subscribers

People subscribed via source and target branches

to all changes: