Lazarus

Installation => macOS / Mac OS X => Topic started by: powerpcer on September 10, 2022, 12:42:17 pm

Title: (Solve by myself) MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 10, 2022, 12:42:17 pm
MACOSX OnUTF8KeyPress for IME input does not work correctly.
If the IME input requires 3 keys, return the word corresponding to each key (so up 3 times),
but not the last word.
i am using the OS bundled Chinese input Method.

refer to attachment
Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 10, 2022, 06:05:47 pm
it seems all input on MacOS 12.5.1 will fire UTF8Keypress.
so, how to setup and let me debug the source in LCL/interfaces/cocoa?
Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: Martin_fr on September 10, 2022, 06:16:21 pm
so, how to setup and let me debug the source in LCL/interfaces/cocoa?

1) Compile the IDE with debug info. Menu Tools > configure build IDE.  Add custom option: -gw3
  Build, and restart
2) Open Project: ide/lazarus.lpi
3) Run / F9

Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 11, 2022, 05:53:21 am
after that, i got
Code: Pascal  [Select][+][-]
  1. error: lazarus debug map object file '/Users/terrylou/Lazarus/lazarus/lcl/units/aarch64-darwin/cocoa/interfaces.o' has changed (actual time is 2022-09-11 11:32:33.000000000, debug map time is 2022-09-11 07:42:26.000000000) since this executable was linked, file will be ignored
  2.  

and click "OK" to continue debugging, but the debugger never work.
Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 11, 2022, 05:59:39 am
when i clean up and build, it shows
Code: Pascal  [Select][+][-]
  1. The project's compiler options has no compile command.
  2. See Project / Compiler Options ... / Compilation
what command do i need to add?
Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: Martin_fr on September 11, 2022, 12:22:16 pm
when i clean up and build, it shows
Code: Pascal  [Select][+][-]
  1. The project's compiler options has no compile command.
  2. See Project / Compiler Options ... / Compilation
what command do i need to add?

None, whenever you change something, you need to build via menu Tools > Build Lazarus.

Make no changes after that => the moment that F9 thinks that you changed something it will recompile individual files. But NOT recreate the executable => and then you get that error "object file.. .changed..."


If you keep getting that error, go to Tools > Configure Build Lazarus
and add to custom options:
-Xg


This will create a folder lazarus.dsym or lazarus.app.dsym.
Should you ever remove the -Xg, then you need to deleted that folder too.


Sorry it's a while since I done this on a Mac. Hence the "if" ad "try".

Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 11, 2022, 04:47:35 pm
thanks Martin,
 i found that KeyEvPrepare in cocoawscommon.pas will fire on every key press.
this catch every CJK char that i typed, but not the last.
the strange is, the IME input dialog not appear.  that different from others APPs
where can i check?

Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: Martin_fr on September 11, 2022, 04:56:07 pm
Unfortunately my expertise is the Debugger.
I am not familiar with the Mac specific LCL/widgetset code.

So someone else has to answer this.

Since the amount of Mac users/devs (compared to other OS) is lower: if no-one answers here, I suggest to post a copy on the mail list (and/or additionally open an issue report on the bug tracker, since this seems to qualify as bug).
Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 11, 2022, 06:13:26 pm
ok, thanks.
Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: Martin_fr on September 11, 2022, 06:34:45 pm
Just remembered, may be important: Add info which controls are affected.

That is either
- TEdit, TMemo, TComboBox
- TSynEdit (IDE Source editor), maybe TRichEdit
- both groups

The first are OS controls, the latter are custom controls.

---
EDIT:

I peaked at your attached project, and you are checking keystrokes in the form.
I have no idea how an IME deals with that after all there is no input element (even though the form can receive keystrokes.)

Testing on Windows, it is possible for an IME to open on a plain TForm.
However it seems to depend on some settings. The main page of the IDE's "About dialog" does not (on Win) allow to open an IME.
Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 12, 2022, 06:36:38 am
on Windows 10, UTF8KeyPress works correctly as its description.
Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 17, 2022, 02:50:40 pm
how can i make packages of cocoaint only?
i got fpcsrc and  fpcsrc/packages/cocoaint,
but i need to rebuild it only.
how could i build this package only?
when i type fpcmake on fpcsrc/packages/cocoaint/
it shows me:
Processing Makefile.fpc
 aarch64-darwin requires: rtl,paszlib,fcl-process,hash,libtar,fpmkunit
 Writing Makefile

Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: AlexTP on September 17, 2022, 02:54:34 pm
This issue was reported by me here
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39908

and duplicate is here
https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39899
Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 17, 2022, 04:56:04 pm
that's different with your behavior.
and i just want to know how to compile package only.
if you know it, just tell me.
Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 19, 2022, 05:13:13 am
after some investigate,
NSTextInputClient.inc==>NSTextInputClientProtocol -->CocoaUtils.inc==>TCocoaInputClient
on TCocoaInputClient, the only validAttributesForMarkedText was fired on debugger.
but not the rest function/procedure.
In Objective-C/SWIFT, the NSTextInputClient method sequence
validAttributesForMarkedText x 3
selectedRange x 2
attributedSubstringforProposedRange x 1
selectedRange x 1
hasMarkedText x 1
validAttributesForMarkedText x 5
setMarkedText  x 1    --> now APP got the character send from IME

but now, only first validAttributesForMarkedText
Title: Re: MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 19, 2022, 03:07:02 pm
by an ugly solution, all done finally.
now UTF8keypress will get the correct character.
and virtualkey and backspace are handle correctly.

fixed with
FPC 3.3.1
Lazarus 2.3.0
 modified interface of cocoa
and packages of cocoa.

zip name with corresponding path.

fix procedure
1. replace those files
2. go to packages folder of fpc
3. fppkg -C /path/to/your/fppkg.cfg install
4. backup your old fpc packages units
5. replace with your new fpc packages units
6. copy rtl folder from old units , (how to build rtl packages?)
7. open lazarus
8. rebuild lazarus.
9. now lazarus should typing chinese correctly. others IME may also be correct.
10. done!!

Title: Re: (Solve by myself) MacOSX on M1 , IME input on Chinese character
Post by: AlexTP on September 26, 2022, 12:29:10 pm
Is it the same as patch in https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39899 ?
Title: Re: (Solve by myself) MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 26, 2022, 04:26:33 pm
Is it the same as patch in https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/39899 ?
more accurate patch, will update to gitlab
Title: Re: (Solve by myself) MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on September 27, 2022, 02:00:00 pm
more ugly patch for chinese IME and japanese Romaji.
due to doCommandBySelector not be called
fix crash on option-U
Title: Re: (Solve by myself) MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on October 05, 2022, 02:41:34 am
more clean patch, do more testing already.
Title: Re: (Solve by myself) MacOSX on M1 , IME input on Chinese character
Post by: powerpcer on October 07, 2022, 10:46:05 am
Japanese Romaji IME, it needs more temporary character handling
than Chinese IME on Client side(Application have to show them, if not use EDIT/MEMO)
because of UTF8KeyPress(), it has no those information.
so we need add more function to support this.
procedure InputClientInsertTextLoc(const utf8: string;loc,len:integer);
--> this procedure should fire a UTF8keypress, but with a string directly and postion and length for replacing.

procedure InputClientSetTextMark(const utf8: string;loc,len:integer);
--> due to Romaji, let application to handle the temporary character display.

procedure InputClientGetPos(const utf8: string;var loc,len:integer);
--> let application to provide where the position of IME should display.

they should map to UTF8StringPress, UTF8StringMark, UTF8InputPos.
TinyPortal © 2005-2018