Lazarus

Installation => Linux => Topic started by: Kunstbanause on January 29, 2009, 11:22:18 pm

Title: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: Kunstbanause on January 29, 2009, 11:22:18 pm
I changed my harddisk on my notebook. After I reinstalled Ubuntu 8.10 x86_64 I now have this weird problem.
When I try to enter text anywhere within the IDE (ObjectInspector, Options, ...) or within a compiled application the pressed key is displayed twice.

For example:
When I try to to enter "FreePascal" it ends up with "FFrreeeePPaassccaall".

Maybe I forgot to install a needed package or it's just any setting of Ubuntu itself, but I do not have any clue where to start to solve the problem and this problem only occurs within Lazarus and any application I compiled.

Greetings,
Marc
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: Bart on January 30, 2009, 02:42:50 pm
This is not a bug, it is new Lazarus feature  >:D
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: Kunstbanause on February 03, 2009, 08:34:33 pm
I just found a bug report for that:

http://bugs.freepascal.org/view.php?id=12600 (http://bugs.freepascal.org/view.php?id=12600)
Title: Re: One keypress, two characters (GTK2 on Fedora 10)
Post by: dstasinski on February 22, 2009, 11:13:16 pm
This same problem started for me as of yesterday.   Any fix available?

Daniel
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: dstasinski on February 23, 2009, 10:51:07 pm
I tracked down the cause of this, SCIM (The Smart Common Input Method platform).  Once disabled, no more double-characters.

Daniel
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: frank_t on March 09, 2009, 03:56:46 am
I tracked down the cause of this, SCIM (The Smart Common Input Method platform).  Once disabled, no more double-characters.

Daniel

I met across this problem, too.
I do enabled scim.
Since you find what's wrong, can you fix this, please?
 :D
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: Vincent Snijders on March 10, 2009, 06:51:38 pm
You don't know how to disable the SCIM?
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: mutex on April 08, 2009, 03:29:24 am
i got the same problem base on fedora10. some one could tell me how to fix it?
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: lonelycorn on April 12, 2009, 06:15:54 pm
i've tried and found that the GTK2 programs lazarus compiled conflict with scim-bridge,a scim binding.GTK1 is ok,and GTK2 programs compiled with other compilers are ok too.
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: mutex on April 22, 2009, 04:45:26 am
i've tried and found that the GTK2 programs lazarus compiled conflict with scim-bridge,a scim binding.GTK1 is ok,and GTK2 programs compiled with other compilers are ok too.

hello
could you inform me how to handle in detail?  and compiled with which compilers?
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: wbeppler on October 24, 2014, 06:25:41 pm
do following:

QT_IM_MODULE=xim <name of program with problem> #  KDE/QT-Anwendungen

or do this: (it worked by my computer)
GTK_IM_MODULE=gtk-im-context-xim <name of program with problem> #  Gnome/GTK-Anwendungen

in detail:
GTK_IM_MODULE=gtk-im-context-xim startlazarus
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: bozcan on January 30, 2015, 11:19:21 am
ALSO I didn't make it, I try everything but it agains types 2 characters when I pressed 1.
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: terry6 on February 01, 2015, 05:32:58 am
lubuntu 14.10
lazarus 1.2.4+dfsg-1
fpc 2.6.4
x86_64-linux-gtk 2

New install. Copied project files from Windows where I have a working exe file. Compiled after removing windows specific files. Everything worked. Ran the compiled file and entering data into an edit field got 2 characters for every one I entered.
Tried editing code and got double characters whenever I typed.
Compiled a test project with just a memo field and when I typed it doubled each letter.
Also ran a compiled file as an executable outside Lazarus and got the same result.
Considering the amount of time this bug has been around I would think there is someone who has a clear solution. Everything works beautifully but I can not type any code or enter data. >:D
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: bozcan on February 02, 2015, 03:20:45 pm
is there any replies to solve this problem _? it's urgent
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: Martin_fr on February 02, 2015, 04:54:04 pm
Probably best to report it as a bug, which as much details (os, gtk version, windownamanger, ...) as possible.

Also best to indicate, if the issue only happens with IM or with/without. (and which keyboard layout is used, does an english layout fix it?)


IIRC some previous issues with key-presses existed only, when the installation was in a virtual machine, or some sort of remote access was used (VNC).
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: terry6 on February 02, 2015, 10:15:52 pm
I am running lubuntu 14.10 exclusively on an Acer ASE360-UA381M desktop with the original Acer keyboard. I am using the default settings for the keyboard which is US English with no changes. I am just using the default driver. The problem only occurs with Lazarus. I have tried changing the keyboard repeat rate and delay to see if there is an effect and there was no change.
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: parcel on February 03, 2015, 12:52:46 am
If it is input method problem, I solved it another way.
But it may not same as above problem.
it tested under UIM.

http://bugs.freepascal.org/view.php?id=26369 (http://bugs.freepascal.org/view.php?id=26369)

Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: terry6 on February 03, 2015, 01:52:56 am
That involves synedit and also it seems to be run under Mint. This problem involves one letter input and two output.'The problem occurs when trying to code and when trying to enter data after compiling.
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: bozcan on February 03, 2015, 08:04:42 am
We are waiting a patch to solve this urgent problem ...
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: Martin_fr on February 03, 2015, 01:45:16 pm
We are waiting a patch to solve this urgent problem ...

Have you reported it on mantis (bugtracker)?

Otherwise the relevant people may never know...

Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: bozcan on February 03, 2015, 04:34:15 pm
I have allready repoted it

http://mantis.freepascal.org/view.php?id=27401
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: bozcan on February 04, 2015, 05:09:10 pm
I solve the problem today, please find the attached picture for more information

click ubuntu software center,
search : IBus
then click GTK +2 support option in bottom addons and click apply updates

that's all
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: terry6 on February 05, 2015, 02:25:59 pm
Doesn't work in Lubuntu Software Center. Only things I can find using IBus search are unrelated to updates. I tried installing "IBus Input Pad Engine" but that had no effect. Can't find anything useful on keyboard input methods.
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: parcel on February 05, 2015, 06:32:46 pm
How about this?

Code: [Select]
Index: components/synedit/synedit.pp
===================================================================
--- components/synedit/synedit.pp (revision 47591)
+++ components/synedit/synedit.pp (working copy)
@@ -1142,6 +1142,10 @@
     property OnSpecialLineColors: TSpecialLineColorsEvent read FOnSpecialLineColors write SetSpecialLineColors;  deprecated;
     property OnSpecialLineMarkup: TSpecialLineMarkupEvent read FOnSpecialLineMarkup write SetSpecialLineMarkup;
     property OnStatusChange: TStatusChangeEvent read fOnStatusChange write fOnStatusChange;
+{$ifdef LCLGtk2}
+  protected
+    procedure GTK_IMComposition(var Message:TMessage); message LM_IM_COMPOSITION;
+{$endif}
   end;
 
   TSynEdit = class(TCustomSynEdit)
@@ -4029,6 +4033,26 @@
   Result := FMarkupManager.Count;
 end;
 
+{$ifdef LCLGtk2}
+procedure TCustomSynEdit.GTK_IMComposition(var Message: TMessage);
+var
+  IMStr:TUTF8Char;
+begin
+  if (not ReadOnly) then
+  begin
+    // delete previous character by selection
+    if Message.WParam and GTK_IM_FLAG_REPLACE<>0 then
+      CommandProcessor(ecSelLeft,#0,nil);
+    // valid string at composition & commit
+    if Message.WParam and (GTK_IM_FLAG_START or GTK_IM_FLAG_END)=0 then
+    begin
+      IMStr:=pchar(Message.LParam);
+      UTF8KeyPress(IMStr);
+    end;
+  end;
+end;
+{$endif}
+
 procedure TCustomSynEdit.SetCaretTypeSize(AType: TSynCaretType; AWidth, AHeight, AXOffs,
   AYOffs: Integer);
 begin
Index: lcl/interfaces/gtk2/gtk2globals.pp
===================================================================
--- lcl/interfaces/gtk2/gtk2globals.pp (revision 47591)
+++ lcl/interfaces/gtk2/gtk2globals.pp (working copy)
@@ -78,6 +78,8 @@
   im_context: PGtkIMContext = nil;
   im_context_widget: PGtkWidget = nil;
   im_context_string: string = '';
+  im_context_use: Boolean = False; //DW
+  im_context_skipDelete: Boolean = False;
 
 procedure ResetDefaultIMContext;
 
@@ -424,6 +426,8 @@
   end;
   im_context_widget:=nil;
   im_context_string:='';
+  im_context_use:=False; //DW
+  im_context_skipDelete:=False;
 end;
 
 procedure AddCharsetEncoding(CharSet: Byte; CharSetReg, CharSetCod: CharSetStr;
Index: lcl/interfaces/gtk2/gtk2proc.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2proc.inc (revision 47591)
+++ lcl/interfaces/gtk2/gtk2proc.inc (working copy)
@@ -2000,7 +2000,8 @@
       end;
       Exit;
     end;
-    Result := (AEvent^.Length > 0) or (GetSpecialChar <> #0);
+    //DW
+    Result := ((not im_context_use) and (AEvent^.Length > 0)) or (GetSpecialChar <> #0);
   end;
   
   function KeyAlreadyHandledByGtk: boolean;
@@ -2007,7 +2008,7 @@
   begin
     Result := false;
     if AWidget = nil then exit;
-   
+
     if GtkWidgetIsA(AWidget, gtk_entry_get_type)
     then begin
       // the gtk_entry handles the following keys
@@ -2361,7 +2362,7 @@
 
       Msg.KeyData := CommonKeyData or (Flags shl 16) or $0001 {TODO:  repeatcount};
 
-      if not KeyAlreadyHandledByGtk
+      if (not KeyAlreadyHandledByGtk) and (not im_context_use)
       then begin
         // send the (Sys)KeyDown message directly to the LCL
         NotifyApplicationUserInput(TControl(TargetObj), Msg.Msg);
@@ -2433,7 +2434,10 @@
         begin
           OldCharacter := Character;
           // send the key after navigation keys were handled
-          Result := TWinControl(LCLObject).IntfUTF8KeyPress(Character, 1, SysKey);
+          if not im_context_use then
+            Result := TWinControl(LCLObject).IntfUTF8KeyPress(Character, 1, SysKey)
+            else
+              Result:=True;
           if Result or (Character = '') then
             // dont' stop key event here, just clear it since we need a keyUp event
             ClearKey
Index: lcl/interfaces/gtk2/gtk2widgetset.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2widgetset.inc (revision 47591)
+++ lcl/interfaces/gtk2/gtk2widgetset.inc (working copy)
@@ -216,11 +216,88 @@
 
 procedure gtk_commit_cb ({%H-}context: PGtkIMContext; const Str: Pgchar;
   {%H-}Data: Pointer); cdecl;
+var
+  Control:TWinControl;
+  Flag:WPARAM;
 begin
   //DebugLn(['gtk_commit_cb ',dbgstr(Str),'="',Str,'"']);
   im_context_string:=Str;
+  { Handle commit string at ending composition,
+    it cannot handled by HandleGTKKeyUpDown }
+  if im_context_use and (im_context_widget<>nil) and (im_context_string<>'') and
+     gtk_widget_is_focus(im_context_widget) then
+      begin
+        Control:=TWinControl(GetNearestLCLObject(im_context_widget));
+        Flag:=GTK_IM_FLAG_COMMIT;
+        if not im_context_skipDelete then
+          Flag:=Flag or GTK_IM_FLAG_REPLACE;
+        SendMessage(Control.Handle,LM_IM_COMPOSITION,Flag,LPARAM(pchar(im_context_string)));
+        im_context_string:='';
+        im_context_skipDelete:=True;
+      end;
 end;
 
+procedure gtk_preedit_start_cb({%H-}context: PGtkIMContext; {%H-}Data: Pointer); cdecl;
+var
+  control:TWinControl;
+  Flag:WPARAM;
+begin
+  if (im_context_widget<>nil) and
+     (gtk_widget_is_focus(im_context_widget)) and
+     (GetNearestLCLObject(im_context_widget) is TCustomControl) then
+  begin
+    im_context_use:=True;
+    im_context_skipDelete:=True;
+    control:=TWinControl(GetNearestLCLObject(im_context_widget));
+    Flag:=GTK_IM_FLAG_START;
+    SendMessage(Control.Handle,LM_IM_COMPOSITION,Flag,LPARAM(Data));
+  end else
+    im_context_use:=False;
+end;
+
+procedure gtk_preedit_end_cb({%H-}context: PGtkIMContext; {%H-}Data: Pointer); cdecl;
+var
+  control:TWinControl;
+  Flag:WPARAM;
+begin
+  im_context_use:=False;
+  if (im_context_widget<>nil) and
+     (gtk_widget_is_focus(im_context_widget)) and
+     (GetNearestLCLObject(im_context_widget) is TCustomControl) then
+  begin
+    im_context_skipDelete:=True;
+    control:=TWinControl(GetNearestLCLObject(im_context_widget));
+    Flag:=GTK_IM_FLAG_END;
+    SendMessage(control.Handle,LM_IM_COMPOSITION,Flag,LPARAM(Data));
+  end;
+end;
+
+procedure gtk_preedit_changed_cb({%H-}context:PGtkIMContext; {%H-}Data:Pointer); cdecl;
+var
+  str:Pgchar;
+  pangoattr:PPangoAttrList;
+  pos:gint;
+  control:TWinControl;
+  Flag:WPARAM;
+begin
+  if im_context_use and (im_context_widget<>nil) and
+    gtk_widget_is_focus(im_context_widget) then
+  begin
+    control:=TWinControl(GetNearestLCLObject(im_context_widget));
+    pos:=1;
+    gtk_im_context_get_preedit_string(context,@str,pangoattr,@pos);
+    im_context_string:=str;
+    g_free(str);
+    pango_attr_list_unref(pangoattr);
+    Flag:=GTK_IM_FLAG_COMPOSITION;
+    if (not im_context_skipDelete) and (Length(im_context_string)>0) then begin
+      Flag:=Flag or GTK_IM_FLAG_REPLACE;
+    end else
+      im_context_skipDelete:=False;
+    SendMessage(control.Handle,LM_IM_COMPOSITION,Flag,LPARAM(pchar(im_context_string)));
+  end;
+end;
+
 {$IfNDef GTK2_2}
 procedure gtkTreeSelectionCountSelectedRows({%H-}model : PGtkTreeModel; {%H-}path : PGtkTreePath;
                                   {%H-}iter : PGtkTreeIter; data : PGint); cdecl;
@@ -985,6 +1062,13 @@
   im_context:=gtk_im_multicontext_new;
   g_signal_connect (G_OBJECT (im_context), 'commit',
     G_CALLBACK (@gtk_commit_cb), nil);
+  //DW
+  g_signal_connect (G_OBJECT (im_context), 'preedit-start',
+    G_CALLBACK (@gtk_preedit_start_cb), nil);
+  g_signal_connect (G_OBJECT (im_context), 'preedit-end',
+    G_CALLBACK (@gtk_preedit_end_cb), nil);
+  g_signal_connect (G_OBJECT (im_context), 'preedit-changed',
+    G_CALLBACK (@gtk_preedit_changed_cb), nil);
   {$IFDEF HASX}
   if IsNoTransientWM then
   begin
Index: lcl/lmessages.pp
===================================================================
--- lcl/lmessages.pp (revision 47591)
+++ lcl/lmessages.pp (working copy)
@@ -93,7 +93,15 @@
   LM_INTERFACELAST  = LM_LCL + 199;
   
   LM_UNKNOWN        = LM_INTERFACELAST + 1;
+  LM_IM_COMPOSITION = LM_UNKNOWN + 1; // gtk IM
 
+  // GTK IM Flags
+  GTK_IM_FLAG_START       = 1;
+  GTK_IM_FLAG_COMPOSITION = 2;
+  GTK_IM_FLAG_END         = 4;
+  GTK_IM_FLAG_COMMIT      = 8;
+  GTK_IM_FLAG_REPLACE     = 16;
+
   //-------------
   //end of messages that are sent to the interface
   //-------------

Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: lainz on April 20, 2015, 01:51:41 pm
Readed almost 12.000 times  :o

I have this problem with Lazarus 1.2.6.

Anyone knows if fixed on SVN?

Edit: I'm using custom drawn target and works fine with edits that I put on my application. At least I can compile something.
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: felipemdc on April 20, 2015, 02:05:34 pm
Great =) I always thought CustomDrawn is useful.

I hope to return to CustomDrawn development when I'm done with Cocoa.
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: tpham3783 on May 12, 2015, 10:14:08 pm
What's the status on this bug?  The only way I can get it to work is to run lazarus as root (tested with lazarus 1.2.4 & 1.4.0).
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: tpham3783 on May 14, 2015, 05:08:35 pm

here is another good reference about this bug:  http://free-pascal-lazarus.989080.n3.nabble.com/Lazarus-Keyboard-handling-messed-up-in-LCL-recent-change-td4041340.html
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: saml on September 08, 2015, 01:43:08 pm
I got the same problem in Xubuntu 14.04 64 bit, even inside some Lazarus menus, e.g. the editboxes in the refactor menu (Right-click > Refactoring > Rename identifier) to name a concrete example, but it really happens more or less everywhere  :(

Tested both with the default that comes with xubuntu:
- Lazarus 1.0.10+dfsg-1
- FPC 2.6.2

... and:

- Lazarus 1.4.2 64bit (deb package)
- FPC 2.6.4 64bit (deb package)

(Xubuntu uses Xfce4, which AFAIK is using gtk2 widgets)

After I removed the scim package completely via synaptic package manager ("Mark for complete removal", then "Apply") and restarted Lazarus, everything works fine again!
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: saml on September 08, 2015, 02:19:23 pm
Doesn't work in Lubuntu Software Center. Only things I can find using IBus search are unrelated to updates. I tried installing "IBus Input Pad Engine" but that had no effect. Can't find anything useful on keyboard input methods.

The command for installing this in the terminal is:

Code: [Select]
sudo apt-get install ibus-gtk
... and for GTK3:

Code: [Select]
sudo apt-get install ibus-gtk3
(Can be found like so:

Code: [Select]
[samuel ~]$ apt-cache search ibus gtk
ibus-gtk - Intelligent Input Bus - GTK+2 support
ibus-gtk3 - Intelligent Input Bus - GTK+3 support
im-config - Input method configuration framework
python-ibus - Intelligent Input Bus - Python support
spectools - Utilities for using the Wi-Spy USB spectrum analyzer hardware

For me though, I get rather inconsistent results. It worked first to completely remove scim, but then it works again even if I re-install scim. *Possibly* because I had installed and removed ibus-gtk there between, so it is not super-easy to pin down exactly the right combination that works, and the one that does not work.

Maybe I'll try and test a little in a virtual machine, to figure this out more exactly ...
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: smartduck on November 19, 2015, 07:52:53 pm
I had the same problem.
I solved it installing both ibus-gtk and ibus-gtk3 via synaptic, then restarted Lubuntu.

Lubuntu 14.04.3 LTS, Lazarus 1.4.4, 32bit.
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: DL7BJ on November 20, 2016, 10:36:58 pm
I have the same problem with installing Lazarus 1.6 and svn version 1.7 Revision 53390 build on a 32 Bit system. I use Lubuntu 16.04.1 LTS.

Enter a caption for a widget, a name for a form or something else results in double chars. I tried to install ibus-gtk install and deinstall scim as described in this thread but nothing solves the problem.

Are there some news about this bug?
Title: Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
Post by: alexander on January 20, 2017, 04:44:46 pm
I also have the same problem.... it's unacceptable..... How do I fix this? I run the latest fpc and latest lazarus...

It is ok to run lazarus with
Code: Pascal  [Select]
  1. GTK_IM_MODULE=gtk-im-context-xim  lazarus
  2.  

But the problem is inherited by all compiled programs!!! And I use opengl, such that I cannot use qt.