Browse Source

* Xterm mouse handling re-engineered.

git-svn-id: trunk@6225 -
daniel 18 years ago
parent
commit
53d640777a
2 changed files with 60 additions and 29 deletions
  1. 18 5
      rtl/unix/keyboard.pp
  2. 42 24
      rtl/unix/mouse.pp

+ 18 - 5
rtl/unix/keyboard.pp

@@ -479,6 +479,7 @@ const
   var MouseEvent: TMouseEvent;
   var MouseEvent: TMouseEvent;
       ch : char;
       ch : char;
       fdsin : tfdSet;
       fdsin : tfdSet;
+      buttonval:byte;
   begin
   begin
     fpFD_ZERO(fdsin);
     fpFD_ZERO(fdsin);
     fpFD_SET(StdInputHandle,fdsin);
     fpFD_SET(StdInputHandle,fdsin);
@@ -488,15 +489,21 @@ const
       fpSelect(StdInputHandle+1,@fdsin,nil,nil,10);
       fpSelect(StdInputHandle+1,@fdsin,nil,nil,10);
     ch:=ttyRecvChar;
     ch:=ttyRecvChar;
     { Other bits are used for Shift, Meta and Ctrl modifiers PM }
     { Other bits are used for Shift, Meta and Ctrl modifiers PM }
-    case (ord(ch)-ord(' ')) and 3  of
+    buttonval:=byte(ch)-byte(' ');
+    {bits 0..1: button status
+     bit  5   : mouse movement while button down.
+     bit  6   : interpret button 1 as button 4
+                interpret button 2 as button 5}
+    case buttonval and 3 of
       0 : {left button press}
       0 : {left button press}
         MouseEvent.buttons:=1;
         MouseEvent.buttons:=1;
       1 : {middle button pressed }
       1 : {middle button pressed }
         MouseEvent.buttons:=2;
         MouseEvent.buttons:=2;
       2 : { right button pressed }
       2 : { right button pressed }
         MouseEvent.buttons:=4;
         MouseEvent.buttons:=4;
-      3 : { no button pressed };
-      end;
+      3 : { no button pressed }
+        MouseEvent.buttons:=0;
+    end;
      if inhead=intail then
      if inhead=intail then
        fpSelect(StdInputHandle+1,@fdsin,nil,nil,10);
        fpSelect(StdInputHandle+1,@fdsin,nil,nil,10);
      ch:=ttyRecvChar;
      ch:=ttyRecvChar;
@@ -505,9 +512,14 @@ const
       fpSelect(StdInputHandle+1,@fdsin,nil,nil,10);
       fpSelect(StdInputHandle+1,@fdsin,nil,nil,10);
      ch:=ttyRecvChar;
      ch:=ttyRecvChar;
      MouseEvent.y:=Ord(ch)-ord(' ')-1;
      MouseEvent.y:=Ord(ch)-ord(' ')-1;
-     if (MouseEvent.buttons<>0) then
-       MouseEvent.action:=MouseActionDown
+     mouseevent.action:=MouseActionMove;
+     if (lastmouseevent.buttons=0) and (mouseevent.buttons<>0) then
+       MouseEvent.action:=MouseActionDown;
+     if (lastmouseevent.buttons<>0) and (mouseevent.buttons=0) then
+       MouseEvent.action:=MouseActionUp;
+(*
      else
      else
+
        begin
        begin
          if (LastMouseEvent.Buttons<>0) and
          if (LastMouseEvent.Buttons<>0) and
             ((LastMouseEvent.X<>MouseEvent.X) or (LastMouseEvent.Y<>MouseEvent.Y)) then
             ((LastMouseEvent.X<>MouseEvent.X) or (LastMouseEvent.Y<>MouseEvent.Y)) then
@@ -522,6 +534,7 @@ const
            end;
            end;
          MouseEvent.Action:=MouseActionUp;
          MouseEvent.Action:=MouseActionUp;
        end;
        end;
+*)
      PutMouseEvent(MouseEvent);
      PutMouseEvent(MouseEvent);
 {$ifdef DebugMouse}
 {$ifdef DebugMouse}
      if MouseEvent.Action=MouseActionDown then
      if MouseEvent.Action=MouseActionDown then

+ 42 - 24
rtl/unix/mouse.pp

@@ -137,21 +137,28 @@ end;
        be able to do this anyway for the NOGPM case), and don't do any libgpm
        be able to do this anyway for the NOGPM case), and don't do any libgpm
        call at all if an xterm mouse is detected.}
        call at all if an xterm mouse is detected.}
 
 
-function detect_xterm_mouse:boolean;
+function detect_xterm_mouse:word;
 
 
 const mouse_terminals:array[0..6] of string[7]=('cons','eterm','gnome',
 const mouse_terminals:array[0..6] of string[7]=('cons','eterm','gnome',
                                                 'konsole','rxvt','screen',
                                                 'konsole','rxvt','screen',
                                                 'xterm');
                                                 'xterm');
+      mouse_1003_capable=[6]; {xterm only for now}
+
 var term:string;
 var term:string;
     i:byte;
     i:byte;
 
 
 begin
 begin
-  detect_xterm_mouse:=true;
+  detect_xterm_mouse:=0;
   term:=fpgetenv('TERM');
   term:=fpgetenv('TERM');
   for i:=low(mouse_terminals) to high(mouse_terminals) do
   for i:=low(mouse_terminals) to high(mouse_terminals) do
     if copy(term,1,length(mouse_terminals[i]))=mouse_terminals[i] then
     if copy(term,1,length(mouse_terminals[i]))=mouse_terminals[i] then
-      exit;
-  detect_xterm_mouse:=false;
+      begin
+        detect_xterm_mouse:=1000;
+        {Can the terminal report all mouse events?}
+        if i in mouse_1003_capable then
+          detect_xterm_mouse:=1003;
+        break;
+      end;
 end;
 end;
 
 
 procedure SysInitMouse;
 procedure SysInitMouse;
@@ -165,19 +172,25 @@ begin
 {  if gpm_fs<>-1 then
 {  if gpm_fs<>-1 then
     runerror(240);}
     runerror(240);}
   {Test wether to use X-terminals.}
   {Test wether to use X-terminals.}
-  if detect_xterm_mouse then
-    begin
-      {Use the xterm mouse.}
-      gpm_fs:=-2;
-      write(#27'[?1001s'); { save old hilit tracking }
-      write(#27'[?1000h'); { enable mouse tracking }
-    end;
+  case detect_xterm_mouse of
+    1000:
+      begin
+        {Use the xterm mouse, report button events only.}
+        gpm_fs:=-1000;
+        {write(#27'[?1001s');} { save old hilit tracking }
+        write(#27'[?1000h'); { enable mouse tracking }
+      end;
+    1003:
+      begin
+        {Use the xterm mouse, report all mouse events.}
+        gpm_fs:=-1003;
+        write(#27'[?1003h'); { enable mouse tracking }
+      end;
+  end;
 {$ifndef NOGPM}
 {$ifndef NOGPM}
+  {Use the gpm mouse?}
   if (gpm_fs=-1) and (vcs_device<>-1) then
   if (gpm_fs=-1) and (vcs_device<>-1) then
     begin
     begin
-      {Use the gpm mouse.}
-
-
       { open gpm }
       { open gpm }
       connect.EventMask:=GPM_MOVE or GPM_DRAG or GPM_DOWN or GPM_UP;
       connect.EventMask:=GPM_MOVE or GPM_DRAG or GPM_DOWN or GPM_UP;
       connect.DefaultMask:=0;
       connect.DefaultMask:=0;
@@ -196,19 +209,24 @@ end;
 
 
 
 
 procedure SysDoneMouse;
 procedure SysDoneMouse;
+
 begin
 begin
-  if gpm_fs<>-1 then
+  case gpm_fs of
+    -1:
       HideMouse;
       HideMouse;
-  if gpm_fs=-2 then
-    begin
-      {xterm mouse}
-      write(#27'[?1000l'); { disable mouse tracking }
-      write(#27'[?1001r'); { Restore old hilit tracking }
-    end
+    -1000:
+      begin
+        {xterm mouse}
+        write(#27'[?1000l'); { disable mouse tracking }
+        {write(#27'[?1001r');} { Restore old hilit tracking }
+      end;
+    -1003:
+      write(#27'[?1003l'); { disable mouse tracking }
 {$ifndef NOGPM}
 {$ifndef NOGPM}
-  else
-    gpm_close
+    else
+      gpm_close;
 {$endif};
 {$endif};
+  end;
   gpm_fs:=-1;
   gpm_fs:=-1;
 end;
 end;
 
 
@@ -221,7 +239,7 @@ var
   e : Tgpm_event;
   e : Tgpm_event;
 {$endif ndef NOGPM}
 {$endif ndef NOGPM}
 begin
 begin
-  if detect_xterm_mouse then
+  if detect_xterm_mouse<>0 then
     SysDetectMouse:=2
     SysDetectMouse:=2
 {$ifndef NOGPM}
 {$ifndef NOGPM}
   else
   else