Oberon Community Platform Forum
November 20, 2019, 07:57:30 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How do get a list of open windows?  (Read 5875 times)
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« on: March 17, 2008, 12:07:05 PM »

I wrote the following code, but it does not work.
triggered when calling manager.GetFirst (); -> ASSERT (lock.HasWriteLock ());
in Win32.WindowManager.Mod module.
What you need to call manager.GetFirst ()? 

    PROCEDURE TestWin(sender, data : ANY);
      VAR
       ss:Utilities.String;
       ww,w:WM.Window;
       i:LONGINT;
      BEGIN
        manager := WM.GetDefaultManager ();
        w:=manager.GetFirst();
        i:=0;
        WHILE w#NIL DO
          ss:=w.GetTitle();
                  AosOut.String("WinCount =");    AosOut.Int(i,5);IF ss#NIL THEN AosOut.String(ss^); END;            AosOut.Ln;             
         INC(i);
        IF i=2 THEN ww:=w; END; (*take random window *)
         w:=manager.GetNext(w);
      END;
      IF (ww#NIL)&(ww.GetTitle()#NIL) THEN
         manager.SetFocus(ww);manager.ToFront(ww); (* push random window to top and activate*)
      END;
   END TestWin;
« Last Edit: March 17, 2008, 01:11:01 PM by BohdanT » Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #1 on: March 17, 2008, 12:15:25 PM »

You need the write lock on the WindowManager object which can be acquired using manager.lock.AcquireWrite (and later released using manager.lock.ReleaseWrite).
Logged
BohdanT
Sr. Member
****
Posts: 271


Life is difficult, but fortunately is short!


WWW
« Reply #2 on: March 17, 2008, 01:09:52 PM »

Thank you very much, it works!
Logged
alys
Newbie
*
Posts: 26


« Reply #3 on: March 17, 2008, 07:53:21 PM »

sorry, i am a novice in oberon and aos, but...
why to read the list of windows author must get WRITE lock?
not some READ lock?
traditionally he need to lock for read, and give opportunity for another threads to get the read lock too. if it is nessesary.
but "write lock" should lock the structure exclusive for current thread. isnt it?

also can windows system be blocked if thread does not unlock this "write lock"?
Logged
staubesv
Administrator
Sr. Member
*****
Posts: 387



« Reply #4 on: March 17, 2008, 08:54:22 PM »

Indeed, that's a good question. I had a look at the window manager code but haven't seen a reason why a read lock should not suffice except that the window manager code forces the use of a write lock by asserting lock.HasWriteLock(). I'll have a closer look at the code tomorrow and change the assert to lock.HasReadLock().
The fact that the window system may be blocked applies also to the read lock: If it is not released, nobody can ever write again...
Logged
alys
Newbie
*
Posts: 26


« Reply #5 on: March 17, 2008, 09:13:16 PM »

I have not seen the code of win manager of aos...but i sense you use only one lock for whole object for any operation?
if it is - it is not good and blocks the manager for a long time.
i think you can have two locks - read and write functions of wm object.
also it is better to remove locks visibility from user and hide locking in member functions of wm.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!