View Issue Details

IDProjectCategoryView StatusLast Update
0032562LazarusIDEpublic2017-10-18 15:22
Reporterfiref Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformPCOSGNU/Linux 
Product Version1.8RC5 
Summary0032562: 5 button mice not supported in Linux - patch available
Descriptionextrabutton1 and 2 do not work in GNU/Linux.

a patch is availbale here : http://forum.lazarus.freepascal.org/index.php/topic,30178.msg262911/topicseen.html
Steps To Reproduce    unit Unit1; {$mode objfpc}{$H+}
     
    interface uses Classes, Forms, Controls , StdCtrls;
    type { TForm1 } TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
      private public
      end;
    var Form1: TForm1; // see also: http://forum.lazarus.freepascal.org/index.php/topic,30178.msg262911/topicseen.html#new
     
    implementation {$R *.lfm} { TForm1 }
    procedure TForm1.Button1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    begin
      if Button=mbExtra1 then Form1.Text:='extra1'; // not working, of course !
      if Button=mbExtra2 then Form1.Text:='extra2';
      if Button=mbLeft then Form1.Text:=' left button';
    end;
    end.
Additional Informationhttp://forum.lazarus.freepascal.org/index.php/topic,30178.msg262911/topicseen.html

a very basic feature for Lazarus, very nice to have!
Tagseditor, lazarus, mouse
Fixed in Revisionr56112, r56122
LazTarget-
WidgetsetGTK 2
Attached Files

Activities

firef

2017-10-17 08:38

reporter  

Juha Manninen

2017-10-17 12:25

developer   ~0103512

Please create a proper patch:
 http://wiki.freepascal.org/Creating_A_Patch

Marco van de Voort

2017-10-17 15:49

manager  

gtk2callback.inc.patch (997 bytes)   
Index: gtk2callback.inc
===================================================================
--- gtk2callback.inc	(revision 56095)
+++ gtk2callback.inc	(working copy)
@@ -2096,6 +2096,8 @@
 
     MessI.Msg := CheckMouseButtonDownUp({%H-}TLCLIntfHandle(widget), AWinControl, LastMouse, EventXY, MouseButton, True);
     MessI.Keys := MessI.Keys or BtnKey;
+    if  BtnKey   in  [MK_XBUTTON1,  MK_XBUTTON2]  then
+       MessI.Keys  :=  MessI.Keys  or  BtnKey   shl  11; 
     case LastMouse.ClickCount of
       2: MessI.Keys := MessI.Keys or MK_DOUBLECLICK;
       3: MessI.Keys := MessI.Keys or MK_TRIPLECLICK;
@@ -2300,7 +2302,7 @@
     2: if not CheckMouseButtonUp(3, LM_MBUTTONUP) then Exit;
     3: if not CheckMouseButtonUp(2, LM_RBUTTONUP) then exit;
     8: if not CheckMouseButtonUp(4, LM_XBUTTONUP) then exit;
-    9: if not CheckMouseButtonUp(4, LM_XBUTTONUP) then exit;
+    9: if not CheckMouseButtonUp(5, LM_XBUTTONUP) then exit;
   else
     begin
       MessI.Msg := LM_NULL;
gtk2callback.inc.patch (997 bytes)   

Marco van de Voort

2017-10-17 15:52

manager   ~0103523

The code has already been significantly changed so finding it is hard.

As far as I can see most has already been committed. I reduced it to the first hunk of the attached patch.

The second hunk is mine, but touches code that was touched by the patch. I wonder if the "9" CASE shouldn't be 5 instead of 4. The original patch parametrises that with button X2.

Juha Manninen

2017-10-17 19:32

developer   ~0103526

I applied the patch in r56112. Thanks Marco.
I changed 4 -> 5 also in function DeliverMouseDownMessage. See:
    9: if not CheckMouseButtonDown(5, MK_XBUTTON2) then Exit;

Please test everybody.
@firef, does it work now?

firef

2017-10-17 21:20

reporter   ~0103530

Last edited: 2017-10-17 21:24

View 2 revisions

Did not work here. Used to work back in 2015 though. Whether it works can easily be tested with the debug target which I provided above, checking for mbExtra1 and 2, given that one has a 5 button mouse inserted.

Juha Manninen

2017-10-17 21:56

developer   ~0103531

Ok, could you provide a patch please.

firef

2017-10-18 03:03

reporter   ~0103543

Last edited: 2017-10-18 03:04

View 2 revisions

I don't have a better patch, sorry.

accorp

2017-10-18 08:57

reporter  

issue-32562-mouse-extra.diff (2,207 bytes)   
Index: lcl/controls.pp
===================================================================
--- lcl/controls.pp	(revision 56113)
+++ lcl/controls.pp	(working copy)
@@ -3107,6 +3107,7 @@
 var
   IsMultiClick: boolean;
   TargetControl: TControl;
+  Button: Byte;
 begin
   Result := LM_NULL;
 
@@ -3159,10 +3160,16 @@
   end;
   LastMouse.Down := AMouseDown;
 
+  // mouse buttons 4,5 share same messages
+  if AButton = 5 then
+    Button := 4
+  else
+    Button := AButton;
+
   if AMouseDown then
-    Result := MSGKINDDOWN[AButton][LastMouse.ClickCount]
+    Result := MSGKINDDOWN[Button][LastMouse.ClickCount]
   else
-    Result := MSGKINDUP[AButton];
+    Result := MSGKINDUP[Button];
 end;
 
 function GetKeyShiftState: TShiftState;
Index: lcl/interfaces/gtk2/gtk2callback.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2callback.inc	(revision 56113)
+++ lcl/interfaces/gtk2/gtk2callback.inc	(working copy)
@@ -2276,11 +2276,11 @@
   MappedXY: TPoint;
   EventXY: TPoint;
 
-  function CheckMouseButtonUp(MouseButton, MsgID: longint): boolean;
+  function CheckMouseButtonUp(MouseButton: longint; BtnShiftState: TShiftStateEnum): boolean;
   begin
-    if MsgID=0 then ;
     MessI.Msg := CheckMouseButtonDownUp({%H-}TLCLIntfHandle(widget),
                            AWinControl, LastMouse, EventXY, MouseButton, False);
+    Include(ShiftState, BtnShiftState);
     Result := True;
  end;
 
@@ -2299,11 +2299,11 @@
   ShiftState := GTKEventStateToShiftState(Event^.State);
 
   case event^.Button of
-    1: if not CheckMouseButtonUp(1, LM_LBUTTONUP) then Exit;
-    2: if not CheckMouseButtonUp(3, LM_MBUTTONUP) then Exit;
-    3: if not CheckMouseButtonUp(2, LM_RBUTTONUP) then exit;
-    8: if not CheckMouseButtonUp(4, LM_XBUTTONUP) then exit;
-    9: if not CheckMouseButtonUp(5, LM_XBUTTONUP) then exit;
+    1: if not CheckMouseButtonUp(1, ssLeft) then Exit;
+    2: if not CheckMouseButtonUp(3, ssMiddle) then Exit;
+    3: if not CheckMouseButtonUp(2, ssRight) then Exit;
+    8: if not CheckMouseButtonUp(4, ssExtra1) then Exit;
+    9: if not CheckMouseButtonUp(5, ssExtra2) then Exit;
   else
     begin
       MessI.Msg := LM_NULL;
issue-32562-mouse-extra.diff (2,207 bytes)   

accorp

2017-10-18 08:59

reporter  

tst-mouse-events.zip (2,798 bytes)

Michl

2017-10-18 11:02

developer   ~0103547

@accorp: Thank you for the patch! Please leave a comment, when you add some. So it wouldn't be forgotten.

I can't test, I haven't such a mice.

Juha Manninen

2017-10-18 12:19

developer   ~0103549

Last edited: 2017-10-18 12:23

View 2 revisions

I applied the patch from accorp. Seems to work. Thanks!

@accorp, yes you should add a comment when you upload a patch. Just write "A patch uploaded" or something.
For example now I would have missed it. I looked at the issue briefly and saw the last comment was from firef.
Maybe there are now ignored patches in other reports for this reason. (?)
Is your real name included in contributors list (shown in Help->About)? I guess not. Please sent it to me by a mail or PM.

accorp

2017-10-18 15:02

reporter   ~0103555

@Michl
I have no 5-button mice either, remapped horizontal scroll via "xinput --set-button-map" :)

@Juha
I'm new to linux, gtk+ and stuff, and prefer to consider my patches not as final solution but as reference point to reduce time for real developer.
Please do not add me to a contributors list ;)

Juha Manninen

2017-10-18 15:22

developer   ~0103557

@accorp, hah! :)
I often have the same feeling. I hope a REAL developer would properly fix my experimental changes.
Who is the REAL developer? Tell me if you find out.

Issue History

Date Modified Username Field Change
2017-10-17 08:38 firef New Issue
2017-10-17 08:38 firef File Added: Drewski patch for mbExtra1 5-button mice.tar.gz
2017-10-17 08:47 firef Tag Attached: lazarus
2017-10-17 08:47 firef Tag Attached: mouse
2017-10-17 08:48 firef Tag Attached: editor
2017-10-17 12:25 Juha Manninen Note Added: 0103512
2017-10-17 15:49 Marco van de Voort File Added: gtk2callback.inc.patch
2017-10-17 15:52 Marco van de Voort Note Added: 0103523
2017-10-17 19:28 Juha Manninen Assigned To => Juha Manninen
2017-10-17 19:28 Juha Manninen Status new => assigned
2017-10-17 19:32 Juha Manninen LazTarget => -
2017-10-17 19:32 Juha Manninen Note Added: 0103526
2017-10-17 19:32 Juha Manninen Status assigned => feedback
2017-10-17 21:20 firef Note Added: 0103530
2017-10-17 21:20 firef Status feedback => assigned
2017-10-17 21:24 firef Note Edited: 0103530 View Revisions
2017-10-17 21:56 Juha Manninen Note Added: 0103531
2017-10-18 03:03 firef Note Added: 0103543
2017-10-18 03:04 firef Note Edited: 0103543 View Revisions
2017-10-18 08:57 accorp File Added: issue-32562-mouse-extra.diff
2017-10-18 08:59 accorp File Added: tst-mouse-events.zip
2017-10-18 11:02 Michl Note Added: 0103547
2017-10-18 12:19 Juha Manninen Fixed in Revision => r56122
2017-10-18 12:19 Juha Manninen Note Added: 0103549
2017-10-18 12:19 Juha Manninen Status assigned => resolved
2017-10-18 12:19 Juha Manninen Resolution open => fixed
2017-10-18 12:20 Juha Manninen Fixed in Revision r56122 => r56112, r56122
2017-10-18 12:23 Juha Manninen Note Edited: 0103549 View Revisions
2017-10-18 15:02 accorp Note Added: 0103555
2017-10-18 15:22 Juha Manninen Note Added: 0103557