* Mouse unit is solely responsible for xterm mouse.

* Improve detection of xterm mouse
  * Improve detection of gpm mouse

git-svn-id: trunk@6082 -
This commit is contained in:
daniel 2007-01-19 21:59:24 +00:00
parent d4bea61f27
commit ac23d1ea3c
3 changed files with 88 additions and 67 deletions

View File

@ -414,6 +414,7 @@ begin
{....................................... First of all, check xterm} {....................................... First of all, check xterm}
(*
term:=fpgetenv('TERM'); term:=fpgetenv('TERM');
if (term<>nil) and (strcomp(term,'xterm')=0) then if (term<>nil) and (strcomp(term,'xterm')=0) then
begin begin
@ -431,6 +432,7 @@ begin
gpm_open:=gpm_fd; gpm_open:=gpm_fd;
exit; exit;
end; end;
*)
{....................................... No xterm, go on} {....................................... No xterm, go on}
{ check whether we know what name the console is: what's with the lib??? } { check whether we know what name the console is: what's with the lib??? }
@ -600,12 +602,14 @@ var next:Pgpm_stst;
begin begin
gpm_tried:=false; { reset the error flag for next time } gpm_tried:=false; { reset the error flag for next time }
(*
if gpm_fd=-2 then { xterm } if gpm_fd=-2 then { xterm }
begin begin
write(#27'[?1000l'#27'[?1001r'); write(#27'[?1000l'#27'[?1001r');
flush(output); flush(output);
end end
else { linux } else { linux }
*)
begin begin
if not gpm_flag then if not gpm_flag then
gpm_close:=0 gpm_close:=0

View File

@ -27,7 +27,7 @@ implementation
uses uses
BaseUnix,Video BaseUnix,Video
{$ifndef NOGPM} {$ifndef NOGPM}
,gpm ,gpm,linuxvcs
{$endif ndef NOGPM} {$endif ndef NOGPM}
; ;
@ -127,27 +127,52 @@ begin
Updatescreen(false); Updatescreen(false);
end; end;
procedure SysInitMouse; function detect_xterm_mouse:boolean;
{$ifndef NOGPM}
var const mouse_terminals:array[0..6] of string[7]=('cons','eterm','gnome',
connect : TGPMConnect; 'konsole','rxvt','screen',
E : Tgpm_event; 'xterm');
{$endif ndef NOGPM} var term:string;
i:byte;
begin begin
detect_xterm_mouse:=true;
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;
end;
procedure SysInitMouse;
{$ifndef NOGPM} {$ifndef NOGPM}
if gpm_fs=-1 then var connect:TGPMConnect;
e:Tgpm_event;
{$endif ndef NOGPM}
begin
{ if gpm_fs<>-1 then
runerror(240);}
{Test wether to use X-terminals.}
if detect_xterm_mouse then
begin begin
{Use the xterm mouse.}
gpm_fs:=-2;
write(#27'[?1001s'); { save old hilit tracking }
write(#27'[?1000h'); { enable mouse tracking }
end;
{$ifndef NOGPM}
if (gpm_fs=-1) and (vcs_device<>-1) then
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;
connect.MinMod:=0; connect.MinMod:=0;
connect.MaxMod:=0; connect.MaxMod:=0;
gpm_fs:=Gpm_Open(connect,0); gpm_fs:=gpm_open(connect,0);
if (gpm_fs=-2) and (fpgetenv('TERM')<>'xterm') then
begin
gpm_fs:=-1;
Gpm_Close;
end;
{ initialize SysLastMouseEvent } { initialize SysLastMouseEvent }
if gpm_fs<>-1 then if gpm_fs<>-1 then
begin begin
@ -155,33 +180,25 @@ begin
GPMEvent2MouseEvent(e,SysLastMouseEvent); GPMEvent2MouseEvent(e,SysLastMouseEvent);
end; end;
end; end;
{ show mousepointer }
if gpm_fs<>-1 then
ShowMouse;
{$else ifdef NOGPM}
if (fpgetenv('TERM')='xterm') then
begin
gpm_fs:=-2;
Write(#27'[?1001s'); { save old hilit tracking }
Write(#27'[?1000h'); { enable mouse tracking }
end;
{$endif NOGPM} {$endif NOGPM}
end; end;
procedure SysDoneMouse; procedure SysDoneMouse;
begin begin
If gpm_fs<>-1 then if gpm_fs<>-1 then
begin
HideMouse; HideMouse;
if gpm_fs=-2 then
begin
{xterm mouse}
write(#27'[?1000l'); { disable mouse tracking }
write(#27'[?1001r'); { Restore old hilit tracking }
end
{$ifndef NOGPM} {$ifndef NOGPM}
Gpm_Close; else
{$else ifdef NOGPM} gpm_close
Write(#27'[?1000l'); { disable mouse tracking } {$endif};
Write(#27'[?1001r'); { Restore old hilit tracking }
{$endif ifdef NOGPM}
gpm_fs:=-1; gpm_fs:=-1;
end;
end; end;
@ -193,19 +210,18 @@ var
e : Tgpm_event; e : Tgpm_event;
{$endif ndef NOGPM} {$endif ndef NOGPM}
begin begin
if detect_xterm_mouse then
SysDetectMouse:=2
{$ifndef NOGPM} {$ifndef NOGPM}
else
begin
if gpm_fs=-1 then if gpm_fs=-1 then
begin begin
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;
connect.MinMod:=0; connect.MinMod:=0;
connect.MaxMod:=0; connect.MaxMod:=0;
gpm_fs:=Gpm_Open(connect,0); gpm_fs:=gpm_open(connect,0);
if (gpm_fs=-2) and (fpgetenv('TERM')<>'xterm') then
begin
Gpm_Close;
gpm_fs:=-1;
end;
end; end;
if gpm_fs>=0 then if gpm_fs>=0 then
begin begin
@ -221,11 +237,8 @@ begin
SysDetectMouse:=Gpm_GetSnapshot(nil) SysDetectMouse:=Gpm_GetSnapshot(nil)
else else
SysDetectMouse:=0; SysDetectMouse:=0;
{$else ifdef NOGPM} end
{ always a mouse deamon present } {$endif NOGPM};
if (fpgetenv('TERM')='xterm') then
SysDetectMouse:=2;
{$endif NOGPM}
end; end;

View File

@ -175,23 +175,27 @@ const term_codes_ansi:Ttermcodes=
#$1B#$28#$42#$1B#$29#$30); {ena_acs} #$1B#$28#$42#$1B#$29#$30); {ena_acs}
const terminal_names:array[0..8] of string[7]=( const terminal_names:array[0..10] of string[7]=(
'ansi', 'ansi',
'cons', 'cons',
'eterm', 'eterm',
'gnome', 'gnome',
'konsole', 'konsole',
'linux', 'linux',
'rxvt',
'screen',
'vt100', 'vt100',
'vt220', 'vt220',
'xterm'); 'xterm');
terminal_data:array[0..8] of Ptermcodes=( terminal_data:array[0..10] of Ptermcodes=(
@term_codes_ansi, @term_codes_ansi,
@term_codes_freebsd, @term_codes_freebsd,
@term_codes_xterm, @term_codes_xterm,
@term_codes_xterm, @term_codes_xterm,
@term_codes_xterm, @term_codes_xterm,
@term_codes_linux, @term_codes_linux,
@term_codes_xterm,
@term_codes_xterm,
@term_codes_vt100, @term_codes_vt100,
@term_codes_vt220, @term_codes_vt220,
@term_codes_xterm); @term_codes_xterm);