One keypress, two characters (GTK2, Ubuntu 8.10 x86_64) lazarus / 1-Linux ---------------------------------------------------------------------- Kunstbanause · 2009-01-29 22:22 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 ---------------------------------------------------------------------- Bart · 2009-01-30 13:42 This is not a bug, it is new Lazarus feature ---------------------------------------------------------------------- Kunstbanause · 2009-02-03 19:34 I just found a bug report for that: http://bugs.freepascal.org/view.php?id=12600 ---------------------------------------------------------------------- dstasinski · 2009-02-22 22:13 This same problem started for me as of yesterday.   Any fix available? Daniel ---------------------------------------------------------------------- dstasinski · 2009-02-23 21:51 I tracked down the cause of this, SCIM (The Smart Common Input Method platform).  Once disabled, no more double-characters. Daniel ---------------------------------------------------------------------- frank_t · 2009-03-09 02:56 Quote from: dstasinski on February 23, 2009, 10:51:07 pmI 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? ---------------------------------------------------------------------- Vincent Snijders · 2009-03-10 17:51 You don't know how to disable the SCIM? ---------------------------------------------------------------------- mutex · 2009-04-08 01:29 i got the same problem base on fedora10. some one could tell me how to fix it? ---------------------------------------------------------------------- lonelycorn · 2009-04-12 16:15 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. ---------------------------------------------------------------------- mutex · 2009-04-22 02:45 Quote from: lonelycorn on April 12, 2009, 06:15:54 pmi'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? ---------------------------------------------------------------------- wbeppler · 2014-10-24 16:25 do following: QT_IM_MODULE=xim #  KDE/QT-Anwendungen or do this: (it worked by my computer) GTK_IM_MODULE=gtk-im-context-xim #  Gnome/GTK-Anwendungen in detail: GTK_IM_MODULE=gtk-im-context-xim startlazarus ---------------------------------------------------------------------- bozcan · 2015-01-30 10:19 ALSO I didn't make it, I try everything but it agains types 2 characters when I pressed 1. ---------------------------------------------------------------------- terry6 · 2015-02-01 04:32 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. ---------------------------------------------------------------------- bozcan · 2015-02-02 14:20 is there any replies to solve this problem _? it's urgent ---------------------------------------------------------------------- Martin_fr · 2015-02-02 15:54 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). ---------------------------------------------------------------------- terry6 · 2015-02-02 21:15 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. ---------------------------------------------------------------------- rasberryrabbit · 2015-02-02 23:52 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 ---------------------------------------------------------------------- terry6 · 2015-02-03 00:52 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. ---------------------------------------------------------------------- bozcan · 2015-02-03 07:04 We are waiting a patch to solve this urgent problem ... ---------------------------------------------------------------------- Martin_fr · 2015-02-03 12:45 Quote from: bozcan on February 03, 2015, 08:04:42 amWe are waiting a patch to solve this urgent problem ... Have you reported it on mantis (bugtracker)? Otherwise the relevant people may never know... ---------------------------------------------------------------------- bozcan · 2015-02-03 15:34 I have allready repoted it http://mantis.freepascal.org/view.php?id=27401 ---------------------------------------------------------------------- bozcan · 2015-02-04 16:09 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 ---------------------------------------------------------------------- terry6 · 2015-02-05 13:25 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. ---------------------------------------------------------------------- rasberryrabbit · 2015-02-05 17:32 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(pcha r(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    //------------- ---------------------------------------------------------------------- lainz · 2015-04-20 11:51 Readed almost 12.000 times  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. ---------------------------------------------------------------------- felipemdc · 2015-04-20 12:05 Great =) I always thought CustomDrawn is useful. I hope to return to CustomDrawn development when I'm done with Cocoa. ---------------------------------------------------------------------- tpham3783 · 2015-05-12 20:14 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). ---------------------------------------------------------------------- tpham3783 · 2015-05-14 15:08 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 ---------------------------------------------------------------------- saml · 2015-09-08 11:43 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! ---------------------------------------------------------------------- saml · 2015-09-08 12:19 Quote from: terry6 on February 05, 2015, 02:25:59 pmDoesn'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 ... ---------------------------------------------------------------------- smartduck · 2015-11-19 18:52 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. ---------------------------------------------------------------------- DL7BJ · 2016-11-20 21:36 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? ---------------------------------------------------------------------- alexander · 2017-01-20 15:44 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i GTK_IM_MODULE=gtk-im-context-xim  lazarus  But the problem is inherited by all compiled programs!!! And I use opengl, such that I cannot use qt. ---------------------------------------------------------------------- justnewbie · 2018-12-02 11:13 Same problem here, double characters. Lazarus 1.8.2, Linux Mint 18.1 64-bit. So far it worked well, but today I got this problem. Any solution? So many years and this huge bug is still there ... ---------------------------------------------------------------------- HeavyUser · 2018-12-02 12:15 Quote from: justnewbie on December 02, 2018, 12:13:24 pmSame problem here, double characters. Lazarus 1.8.2, Linux Mint 18.1 64-bit. So far it worked well, but today I got this problem. Any solution? So many years and this huge bug is still there ... https://forum.lazarus.freepascal.org/index.php/topic,39799.msg274142.h tml#msg274142 I'm not a linux user thank god. so I'll leave others to answer the long time bug. ---------------------------------------------------------------------- justnewbie · 2018-12-02 14:57 Quote from: HeavyUser on December 02, 2018, 01:15:38 pmQuote from: justnewbie on December 02, 2018, 12:13:24 pmSame problem here, double characters. Lazarus 1.8.2, Linux Mint 18.1 64-bit. So far it worked well, but today I got this problem. Any solution? So many years and this huge bug is still there ... https://forum.lazarus.freepascal.org/index.php/topic,39799.msg274142.h tml#msg274142 I'm not a linux user thank god. so I'll leave others to answer the long time bug. Thank you, but it did not solve the problem. ibus-gtk and ibus-gtk3 installed. Input method >> none. Doesn't work. I can't believe that this bug is at least 10 years old and still exists. It makes impossible to work with Lazarus. Any other solution? ---------------------------------------------------------------------- Handoko · 2018-12-02 15:30 Have you try the solution in the link below? https://forum.lazarus.freepascal.org/index.php/topic,39213.msg268286.h tml#msg268286 It works for me on Ubuntu. Don't forget you need to reboot your computer to see the effect. ---------------------------------------------------------------------- justnewbie · 2018-12-02 15:34 Quote from: Handoko on December 02, 2018, 04:30:49 pmHave you try the solution in the link below? https://forum.lazarus.freepascal.org/index.php/topic,39213.msg268286.h tml#msg268286 It works for me on Ubuntu. Don't forget you need to reboot your computer to see the effect. Yes, I did that and restart Linux, but nothing changed. ---------------------------------------------------------------------- justnewbie · 2018-12-02 17:10 OK, problem solved. I found JD's post here https://forum.lazarus.freepascal.org/index.php/ topic,39799.msg274142.html#msg274142 and he wrote "Creating a file input_method.sh in my home directory". It was misleading, because the proper folder is the /etc/profile.d. Thank you for the help ---------------------------------------------------------------------- Angbor · 2019-03-05 10:18 Yes, guys! It really works!! (I have Xubuntu)