Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2018-03

TStringGrid and cancelling a modal form

10 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

Running on (Debian) Linux on AMD64 or ARM, Lazarus 1.6.4 and FPC 3.0.2, I'm seeing different behaviour depending on whether a program uses Qt or GTK2. The program changes the hardware configuration of a mouse (Logitech G600) using hidraw, and as such needs to run with root privilege (e.g. kdesudo or sudo -E).

On the main form I've got (a tabbed notebook containing multiple instances of) a TStringGrid. The OnSelection event invokes a modal form (containing nothing of significant complexity) with OK and Cancel buttons, and stripped down looks like this:

procedure TFormLG600.StringGridMode1UnshiftedSelection(Sender: TObject;
aCol, aRow: Integer);
begin
{...}
   if ButtonsAndKeys.ShowModal() = mrOk then begin
{...}
   end
end;

This is fine if built for Qt, but if built for GTK2 what I see is that after the modal form is exited any mouse activity over the grid appears to cause an erratic multicell selection and the modal form immediately pops up again. This is reproducible if the Cancel button is pressed, and in at least some cases after OK.

I've seen indeterminate discussion of this in the foramina, and have followed up the indicated wiki pages etc. Does anybody have any suggestions, preferably not along the lines of "don't use GTK2" since I was thinking of sticking this on Sourceforge and that restriction would probably be unpopular?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

zeljko
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 33 lines
Running on (Debian) Linux on AMD64 or ARM, Lazarus 1.6.4 and FPC 3.0.2, I'm seeing different behaviour depending on whether a program uses Qt or GTK2. The program changes the hardware configuration of a mouse (Logitech G600) using hidraw, and as such needs to run with root privilege (e.g. kdesudo or sudo -E). On the main form I've got (a tabbed notebook containing multiple instances of) a TStringGrid. The OnSelection event invokes a modal form (containing nothing of significant complexity) with OK and Cancel buttons, and stripped down looks like this: procedure TFormLG600.StringGridMode1UnshiftedSelection(Sender: TObject; aCol, aRow: Integer); begin {...} if ButtonsAndKeys.ShowModal() = mrOk then begin {...} end end; This is fine if built for Qt, but if built for GTK2 what I see is that after the modal form is exited any mouse activity over the grid appears to cause an erratic multicell selection and the modal form immediately pops up again. This is reproducible if the Cancel button is pressed, and in at least some cases after OK. I've seen indeterminate discussion of this in the foramina, and have followed up the indicated wiki pages etc. Does anybody have any suggestions, preferably not along the lines of "don't use GTK2" since I was thinking of sticking this on Sourceforge and that restriction would probably be unpopular?

hmm, try LCLIntf.SetCapture(0) after closing modal form , just to isolate capture problems.

zeljko

Reply by email

José Mejuto
to Mark Morgan Lloyd: Running on (Debian) Linux on AMD64 or ARM, Lazarus 1.6.4 and FPC 3.0.2, I'm seeing…
Mark Morgan Lloyd wrote 10 lines
Running on (Debian) Linux on AMD64 or ARM, Lazarus 1.6.4 and FPC 3.0.2, I'm seeing different behaviour depending on whether a program uses Qt or GTK2. The program changes the hardware configuration of a mouse (Logitech G600) using hidraw, and as such needs to run with root privilege (e.g. kdesudo or sudo -E). On the main form I've got (a tabbed notebook containing multiple instances of) a TStringGrid. The OnSelection event invokes a modal form (containing nothing of significant complexity) with OK and Cancel buttons, and stripped down looks like this:

Hello,

Just for testing the OnSelection is raised by mouse click ? If the answer is yes, try to click the cell and keep the mouse button pressed. If the form appears the grid is still waiting for a MOUSE_UP (thinking you are holding MOUSE_DOWN to perform a selection) and the modal form has its own queue, so MOUSE_UP never arrives.

Reply by email

Mark Morgan Lloyd
to zeljko: hmm, try LCLIntf.SetCapture(0) after closing modal form , just to isolate capture…
zeljko wrote 37 lines
On 03/12/2018 06:25 PM, Mark Morgan Lloyd via Lazarus wrote: > Running on (Debian) Linux on AMD64 or ARM, Lazarus 1.6.4 and FPC > 3.0.2, I'm seeing different behaviour depending on whether a program > uses Qt or GTK2. The program changes the hardware configuration of a > mouse (Logitech G600) using hidraw, and as such needs to run with root > privilege (e.g. kdesudo or sudo -E). > > On the main form I've got (a tabbed notebook containing multiple > instances of) a TStringGrid. The OnSelection event invokes a modal > form (containing nothing of significant complexity) with OK and Cancel > buttons, and stripped down looks like this: > > procedure TFormLG600.StringGridMode1UnshiftedSelection(Sender: > TObject; aCol, aRow: Integer); > > begin > {...} >    if ButtonsAndKeys.ShowModal() = mrOk then begin > {...} >    end > end; > > This is fine if built for Qt, but if built for GTK2 what I see is that > after the modal form is exited any mouse activity over the grid > appears to cause an erratic multicell selection and the modal form > immediately pops up again. This is reproducible if the Cancel button > is pressed, and in at least some cases after OK. > > I've seen indeterminate discussion of this in the foramina, and have > followed up the indicated wiki pages etc. Does anybody have any > suggestions, preferably not along the lines of "don't use GTK2" since > I was thinking of sticking this on Sourceforge and that restriction > would probably be unpopular? > hmm, try LCLIntf.SetCapture(0) after closing modal form , just to isolate capture problems.

Like this?

} end

; LCLIntf.SetCapture(0)

end { TFormLG600.StringGridMode1UnshiftedSelection } ;

No obvious change- what should I be looking for?

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to José Mejuto: Just for testing the OnSelection is raised by mouse click ? If the answer is yes, try to…
José Mejuto wrote 13 lines
El 12/03/2018 a las 18:25, Mark Morgan Lloyd via Lazarus escribió:> On the main form I've got (a tabbed notebook containing multiple > instances of) a TStringGrid. The OnSelection event invokes a modal form > (containing nothing of significant complexity) with OK and Cancel > buttons, and stripped down looks like this: Hello, Just for testing the OnSelection is raised by mouse click ? If the answer is yes, try to click the cell and keep the mouse button pressed. If the form appears the grid is still waiting for a MOUSE_UP (thinking you are holding MOUSE_DOWN to perform a selection) and the modal form has its own queue, so MOUSE_UP never arrives.

Yes, the modal form appears while the mouse button is held down (for both GTK2 and Qt).

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

zeljko
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 17 lines
On 12/03/18 17:45, José Mejuto via Lazarus wrote: > El 12/03/2018 a las 18:25, Mark Morgan Lloyd via Lazarus escribió:> > On the main form I've got (a tabbed notebook containing multiple > > instances of) a TStringGrid. The OnSelection event invokes a modal > form > (containing nothing of significant complexity) with OK and > Cancel > buttons, and stripped down looks like this: > Hello, > Just for testing the OnSelection is raised by mouse click ? If the > answer is yes, try to click the cell and keep the mouse button > pressed. If the form appears the grid is still waiting for a MOUSE_UP > (thinking you are holding MOUSE_DOWN to perform a selection) and the > modal form has its own queue, so MOUSE_UP never arrives. Yes, the modal form appears while the mouse button is held down (for both GTK2 and Qt).

So, yes, seem that grid expects mouseup

Reply by email

Mark Morgan Lloyd
to zeljko
zeljko wrote 20 lines
On 03/12/2018 08:05 PM, Mark Morgan Lloyd via Lazarus wrote: > On 12/03/18 17:45, José Mejuto via Lazarus wrote: >> El 12/03/2018 a las 18:25, Mark Morgan Lloyd via Lazarus escribió:> > >> On the main form I've got (a tabbed notebook containing multiple > >> instances of) a TStringGrid. The OnSelection event invokes a modal >> form > (containing nothing of significant complexity) with OK and >> Cancel > buttons, and stripped down looks like this: >> Hello, >> Just for testing the OnSelection is raised by mouse click ? If the >> answer is yes, try to click the cell and keep the mouse button >> pressed. If the form appears the grid is still waiting for a MOUSE_UP >> (thinking you are holding MOUSE_DOWN to perform a selection) and the >> modal form has its own queue, so MOUSE_UP never arrives. > > Yes, the modal form appears while the mouse button is held down (for > both GTK2 and Qt). > So, yes, seem that grid expects mouseup

Is there a portable way this can be sent? Otherwise I presume I could fudge it with something like QueueAsyncCall()... unless that also went through before the mouse activity was sorted out.

I'm fairly keen to hack this in such a way that it's not tied to one version of the LCL since I want this program to be fairly easy to build even for people with an old (or no existing) copy of Lazarus etc.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

José Mejuto
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 13 lines
>> Yes, the modal form appears while the mouse button is held down (for >> both GTK2 and Qt). >> > > So, yes, seem that grid expects mouseup Is there a portable way this can be sent? Otherwise I presume I could fudge it with something like QueueAsyncCall()... unless that also went through before the mouse activity was sorted out. I'm fairly keen to hack this in such a way that it's not tied to one version of the LCL since I want this program to be fairly easy to build even for people with an old (or no existing) copy of Lazarus etc.

Hello,

I think the proper solution is to instruct GTK2 to use the MOUSE_UP event, but meanwhile QueueAsyncCall will not be the solution as when the AsyncCall will be processed grid will be still waiting for MOUSE_UP, so my solution would be add a MOUSE_UP and MOUSE_DOWN handlers, something like this in pseudo code:

MOUSE_DOWN:
   SelectChanged:=false;
ON_SELECT:
   SelectChanged:=true;
MOUSE_UP:
   if SelectChanged then Form.ShowModal();

Reply by email

Mark Morgan Lloyd
to José Mejuto
José Mejuto wrote 18 lines
El 13/03/2018 a las 9:21, Mark Morgan Lloyd via Lazarus escribió:>>> Yes, the modal form appears while the mouse button is held down (for >>> both GTK2 and Qt).>>>>>>> So, yes, seem that grid expects mouseup> > Is there a portable way this can be sent? Otherwise I presume I could > fudge it with something like QueueAsyncCall()... unless that also went> through before the mouse activity was sorted out.> > I'm fairly keen to hack this in such a way that it's not tied to one > version of the LCL since I want this program to be fairly easy to build > even for people with an old (or no existing) copy of Lazarus etc. Hello, I think the proper solution is to instruct GTK2 to use the MOUSE_UP event, but meanwhile QueueAsyncCall will not be the solution as when the AsyncCall will be processed grid will be still waiting for MOUSE_UP, so my solution would be add a MOUSE_UP and MOUSE_DOWN handlers, something like this in pseudo code: MOUSE_DOWN:   SelectChanged:=false; ON_SELECT:   SelectChanged:=true; MOUSE_UP:   if SelectChanged then Form.ShowModal();

Thanks, I'd just about worked that one out. I'll try later- I'm spending the day helping with some flocking sheep ;-)

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Mark Morgan Lloyd
to José Mejuto: I think the proper solution is to instruct GTK2 to use the MOUSE_UP event, but meanwhile…
José Mejuto wrote 12 lines
El 13/03/2018 a las 9:21, Mark Morgan Lloyd via Lazarus escribió:>>> Yes, the modal form appears while the mouse button is held down (for >>> both GTK2 and Qt).>>>>>>> So, yes, seem that grid expects mouseup> I think the proper solution is to instruct GTK2 to use the MOUSE_UP event, but meanwhile QueueAsyncCall will not be the solution as when the AsyncCall will be processed grid will be still waiting for MOUSE_UP, so my solution would be add a MOUSE_UP and MOUSE_DOWN handlers, something like this in pseudo code: MOUSE_DOWN:   SelectChanged:=false; ON_SELECT:   SelectChanged:=true; MOUSE_UP:   if SelectChanged then Form.ShowModal();

I can confirm that that approach appears reliable.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email