Forum > Linux

[Solved] Get notified when monitors count/resolution changed

<< < (2/2)

Fred vS:
Hello.

You may try with this:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    procedure TXRandREventWatcherThread.Execute;    var        RootWnd: TWindow;    begin      writeln(ClassName, '::Execute() started');           RootWnd := RootWindow(Display, DefaultScreen(Display));           XRRSelectInput(Display, RootWnd, FEventMask {NoEventMask});      while True do        begin        if XPending(Display) > 0  then         begin           XNextEvent(Display, @FLastEvent);           DebugLn('Recieved event: %d', [FLastEvent._type]);  // event 89 is change of resolution           Synchronize(@Notify);         end;       if Terminated then Break;               sleep(100);       end;       writeln(ClassName, '::Execute() ended');    end;
And with this to destroy form:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormDestroy(Sender: TObject);begin  w.Terminate;  w.WaitFor;  // Add this  w.Free;end;

MarkMLl:
I broadly agree with Fred here, but would add a detail.

I few months ago I was looking at something- I think it was custom code for handling TCP messages but forget the detail- and found it was convenient to put a message handler in a thread to handle incoming messages and marshal them into a queue.

In order to terminate neatly I set up a single-thread HUP handler. That worked fine if the HUP was sent from the main thread, but not if it was sent from outside the program e.g. as a hint that a configuration file should be re-read. After much digging into documentation I learnt that that was more or less the expected behaviour.

So even if you are in a thread, if you have to monitor the Terminated flag you need to take steps not to block on anything else: find out how to poll, and/or make sure that you can use a timeout on any function if necessary by using fpselect().

And I don't know where that leaves you with low-level X11 events :-/

MarkMLl

artem101:

--- Quote from: Fred vS on March 28, 2023, 04:17:22 pm ---You may try with this:

--- End quote ---

It works! Thank you very much.

Navigation

[0] Message Index

[*] Previous page

Go to full version