Recent

Author Topic: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)  (Read 39975 times)

terry6

  • Newbie
  • Posts: 6
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #15 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.

parcel

  • Full Member
  • ***
  • Posts: 143
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #16 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


terry6

  • Newbie
  • Posts: 6
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #17 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.

bozcan

  • Newbie
  • Posts: 5
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #18 on: February 03, 2015, 08:04:42 am »
We are waiting a patch to solve this urgent problem ...

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #19 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...


bozcan

  • Newbie
  • Posts: 5
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #20 on: February 03, 2015, 04:34:15 pm »

bozcan

  • Newbie
  • Posts: 5
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #21 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

terry6

  • Newbie
  • Posts: 6
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #22 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.

parcel

  • Full Member
  • ***
  • Posts: 143
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #23 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
   //-------------


lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #24 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.
« Last Edit: April 20, 2015, 02:00:29 pm by 007 »

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #25 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.

tpham3783

  • Newbie
  • Posts: 4
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #26 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).


saml

  • New Member
  • *
  • Posts: 20
  • Developer, Biotech Engineer, PhD Student
    • Bionics IT
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #28 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!
« Last Edit: September 08, 2015, 01:45:11 pm by saml »

saml

  • New Member
  • *
  • Posts: 20
  • Developer, Biotech Engineer, PhD Student
    • Bionics IT
Re: One keypress, two characters (GTK2, Ubuntu 8.10 x86_64)
« Reply #29 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 ...

 

TinyPortal © 2005-2018