summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-10-19 23:02:25 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-10-19 23:02:25 +0000
commitd3990d8e3066882a3b55f985e8532b29cf62ef2e (patch)
tree07f4c0076a066ace3c0bc3e7bb46a72defaa13bf
parentc6891d52382d3eec25a781ffab6ad4fe22bf4f4c (diff)
downloadfpGUI-d3990d8e3066882a3b55f985e8532b29cf62ef2e.tar.xz
X11: Increased the main evenloop timeout to prevent lag in GUI updates.
* X11: Rewrote the eventloop timeout code with extra comments.
-rw-r--r--src/corelib/x11/fpg_x11.pas38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/corelib/x11/fpg_x11.pas b/src/corelib/x11/fpg_x11.pas
index 010fda63..61556178 100644
--- a/src/corelib/x11/fpg_x11.pas
+++ b/src/corelib/x11/fpg_x11.pas
@@ -842,6 +842,7 @@ var
KeySym: TKeySym;
Popup: TfpgWidget;
status: TStatus;
+ needToWait: boolean;
// debug purposes only
procedure PrintKeyEvent(const event: TXEvent);
@@ -883,9 +884,11 @@ var
begin
xfd := XConnectionNumber(display);
-
+ XFlush(display);
+(*
repeat
- if (atimeoutms >= 0) and (XPending(display) <= 0) then
+
+ if (atimeoutms >= 0) and (XPending(display) < 1) then { there are no X messages }
begin
if Assigned(FOnIdle) then
OnIdle(self);
@@ -894,14 +897,37 @@ begin
// Poll would be better but FPC has no official poll interface (if I'm right)
fpFD_ZERO(rfds);
fpFD_SET(xfd, rfds);
- r := fpSelect(xfd + 1, @rfds, nil, nil, atimeoutms);
+ r := fpSelect(xfd + 1, @rfds, nil, nil, {atimeoutms} 50);
- if r <= 0 then
+ if r < 1 then
Exit; // no event received.
end;
- XNextEvent(display, @ev);
+
+ XNextEvent(display, @ev);
until (not XFilterEvent(@ev, X.None));
-
+*)
+
+ needToWait := True;
+ if XPending(display) > 0 then // We have a X message to process
+ begin
+ XNextEvent(display, @ev);
+ needToWait := False;
+ end;
+
+ if needToWait then // No X messages to process (we are idle). So do a timeout wait
+ begin
+ if Assigned(FOnIdle) then
+ OnIdle(self);
+ fpFD_ZERO(rfds);
+ fpFD_SET(xfd, rfds);
+ r := fpSelect(xfd + 1, @rfds, nil, nil, {atimeoutms} 50);
+ if r <> 0 then // We got a X event or the timeout happened
+ XNextEvent(display, @ev)
+ else
+ Exit; // nothing further to do here!
+ end;
+
+
// if the event filter returns true then it ate the message
if Assigned(FEventFilter) and FEventFilter(ev) then
exit; // no more processing required for that event