mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-14 10:49:20 +02:00
* Xterm mouse handling re-engineered.
git-svn-id: trunk@6225 -
This commit is contained in:
parent
60d19ea1e6
commit
53d640777a
@ -479,6 +479,7 @@ const
|
||||
var MouseEvent: TMouseEvent;
|
||||
ch : char;
|
||||
fdsin : tfdSet;
|
||||
buttonval:byte;
|
||||
begin
|
||||
fpFD_ZERO(fdsin);
|
||||
fpFD_SET(StdInputHandle,fdsin);
|
||||
@ -488,15 +489,21 @@ const
|
||||
fpSelect(StdInputHandle+1,@fdsin,nil,nil,10);
|
||||
ch:=ttyRecvChar;
|
||||
{ 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}
|
||||
MouseEvent.buttons:=1;
|
||||
1 : {middle button pressed }
|
||||
MouseEvent.buttons:=2;
|
||||
2 : { right button pressed }
|
||||
MouseEvent.buttons:=4;
|
||||
3 : { no button pressed };
|
||||
end;
|
||||
3 : { no button pressed }
|
||||
MouseEvent.buttons:=0;
|
||||
end;
|
||||
if inhead=intail then
|
||||
fpSelect(StdInputHandle+1,@fdsin,nil,nil,10);
|
||||
ch:=ttyRecvChar;
|
||||
@ -505,9 +512,14 @@ const
|
||||
fpSelect(StdInputHandle+1,@fdsin,nil,nil,10);
|
||||
ch:=ttyRecvChar;
|
||||
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
|
||||
|
||||
begin
|
||||
if (LastMouseEvent.Buttons<>0) and
|
||||
((LastMouseEvent.X<>MouseEvent.X) or (LastMouseEvent.Y<>MouseEvent.Y)) then
|
||||
@ -522,6 +534,7 @@ const
|
||||
end;
|
||||
MouseEvent.Action:=MouseActionUp;
|
||||
end;
|
||||
*)
|
||||
PutMouseEvent(MouseEvent);
|
||||
{$ifdef DebugMouse}
|
||||
if MouseEvent.Action=MouseActionDown then
|
||||
|
@ -137,21 +137,28 @@ end;
|
||||
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.}
|
||||
|
||||
function detect_xterm_mouse:boolean;
|
||||
function detect_xterm_mouse:word;
|
||||
|
||||
const mouse_terminals:array[0..6] of string[7]=('cons','eterm','gnome',
|
||||
'konsole','rxvt','screen',
|
||||
'xterm');
|
||||
mouse_1003_capable=[6]; {xterm only for now}
|
||||
|
||||
var term:string;
|
||||
i:byte;
|
||||
|
||||
begin
|
||||
detect_xterm_mouse:=true;
|
||||
detect_xterm_mouse:=0;
|
||||
term:=fpgetenv('TERM');
|
||||
for i:=low(mouse_terminals) to high(mouse_terminals) do
|
||||
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;
|
||||
|
||||
procedure SysInitMouse;
|
||||
@ -165,19 +172,25 @@ begin
|
||||
{ if gpm_fs<>-1 then
|
||||
runerror(240);}
|
||||
{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}
|
||||
{Use the gpm mouse?}
|
||||
if (gpm_fs=-1) and (vcs_device<>-1) then
|
||||
begin
|
||||
{Use the gpm mouse.}
|
||||
|
||||
|
||||
{ open gpm }
|
||||
connect.EventMask:=GPM_MOVE or GPM_DRAG or GPM_DOWN or GPM_UP;
|
||||
connect.DefaultMask:=0;
|
||||
@ -196,19 +209,24 @@ end;
|
||||
|
||||
|
||||
procedure SysDoneMouse;
|
||||
|
||||
begin
|
||||
if gpm_fs<>-1 then
|
||||
case gpm_fs of
|
||||
-1:
|
||||
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}
|
||||
else
|
||||
gpm_close
|
||||
else
|
||||
gpm_close;
|
||||
{$endif};
|
||||
end;
|
||||
gpm_fs:=-1;
|
||||
end;
|
||||
|
||||
@ -221,7 +239,7 @@ var
|
||||
e : Tgpm_event;
|
||||
{$endif ndef NOGPM}
|
||||
begin
|
||||
if detect_xterm_mouse then
|
||||
if detect_xterm_mouse<>0 then
|
||||
SysDetectMouse:=2
|
||||
{$ifndef NOGPM}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user