[Date Prev] [Date Index] [Date Next]
[Thread Prev] [Thread Index] [Thread Next]

[xyzzy:03579] Re: 表示色



こんばんわ。奈由太です。

Tetsuya Kamei <kamei@xxxxxxxxxxxx> wrote:

> | というわけで、いちばんまっとうと思われる方法でやってみました。xyzzy に
> | 反映していただけると嬉しいです。
> 
> どーもです。ただ、これだけではだめなんです。変換中でも
> メニューやいくつかのキーは素通しでくるので、その場合に 
> quit できなくなってしまいます。また、変換中にダイアロ
> グを出して確定とかすると、ENDCOMPOSITION が toplevel 
> に来ないので、

色々問題があるものですね。

フックを使って色々やってみました。lisp を動かすトリガが、WM_KEYDOWN の
みで、しかも、Control/Shift/Alt/Windows キーがトリガにはならないのなら、
以下のパッチでうまく行くと思います。…マウスはトリガになれるんでしたっ
け?

> フラグを立てといてコマンド実行の前後で何
> とかしてやるにしても面倒だなということで、今のところほ
> ったらかしてあるのですが。何かいい手はないですかね?

結局、lisp が動く直前に Register して、動き終わったあとに Unregister 
するというのが一番いいやり方だとは思うのですが。lisp はどこで動かして
いるのだろう…

--
∩∩ | TAGA Nayuta <nayuta@xxxxxxxxxxxxxxxxxx> 多賀 奈由太
"∪" | Department of Information Science, University of Tokyo

diff -c -N xyzzy/src-orig/Makefile xyzzy/src/Makefile
*** xyzzy/src-orig/Makefile	Sun Sep 12 18:18:02 1999
--- xyzzy/src/Makefile	Tue Nov 16 20:08:11 1999
***************
*** 154,166 ****
  	dpp $< $@
  
  all: $(OUTDIR) dpp.exe includes ../xyzzyenv.exe \
!      $(FINAL_TARGET) ../xyzzycli.exe libxpi.lib
  
  includes: vars-decl.h fns-decl.h msgcode.h
  
! $(OUTDIR)/$(BUILD): $(OBJS) $(PRIVCTRLOBJS) $(OUTDIR)/xyzzy.res
  	$(LD) $(LDFLAGS) -out:$@ $(OBJS) $(PRIVCTRLOBJS) \
! 		-subsystem:windows $(LIBS) $(OUTDIR)/xyzzy.res
  
  $(OUTDIR): force
  	-@if not exist $(OUTDIR)/nul mkdir $(OUTDIR)
--- 154,167 ----
  	dpp $< $@
  
  all: $(OUTDIR) dpp.exe includes ../xyzzyenv.exe \
!      $(FINAL_TARGET) ../xyzzycli.exe libxpi.lib ../xyzzy.dll
  
  includes: vars-decl.h fns-decl.h msgcode.h
  
! $(OUTDIR)/$(BUILD): $(OBJS) $(PRIVCTRLOBJS) $(OUTDIR)/xyzzy.res \
! 	$(OUTDIR)/xyzzy.lib
  	$(LD) $(LDFLAGS) -out:$@ $(OBJS) $(PRIVCTRLOBJS) \
! 		-subsystem:windows $(LIBS) xyzzy.lib $(OUTDIR)/xyzzy.res
  
  $(OUTDIR): force
  	-@if not exist $(OUTDIR)/nul mkdir $(OUTDIR)
***************
*** 175,185 ****
--- 176,188 ----
  	rm -f gen-ktab.obj gen-ktab.exe gen-msg.obj gen-msg.exe
  	rm -f gen-vinf.obj gen-vinf.exe verinfo.h
  	rm -f dpp.exe dpp.obj num-arith.h
+ 	rm -f $(OUTDIR)\hook.obj $(OUTDIR)\xyzzy.lib 
  
  distclean: clean
  	rm -f vars-decl.h fns-decl.h symtable.cc chtab.cc msgcode.h \
  	  dumpver.cc msgdef.cc kanjitab.h xdde.obj \
  	  xyzzycli.obj xyzzycli.exe xyzzyenv.obj xyzzyenv.exe \
+ 	  xyzzy.dll \
  	  xyzzycli.res xyzzyenv.res libxpi.lib xpi.obj \
  	  vc40.idb vc40.pdb *.aps XTAGS #* *~ \
  	  $(PRIVCTRLDIR)/#* $(PRIVCTRLDIR)/*~
***************
*** 208,213 ****
--- 211,237 ----
  
  xyzzycli.res: xyzzycli.h
  
+ ../xyzzy.dll: xyzzy.dll
+ 	copy xyzzy.dll .. > nul
+ 
+ DLL_OBJS=$(OUTDIR)/hook.obj
+ !IF "$(CFG)" == "d"
+ 
+ xyzzy.dll: $(DLL_OBJS)
+ 	link $(DLL_OBJS) -out:xyzzy.dll -debug:full -debugtype:cv /NODEFAULTLIB /INCREMENTAL:NO /PDB:NONE /RELEASE /NOLOGO -entry:_DllMainCRTStartup@12 -dll libcmt.lib kernel32.lib user32.lib 
+ 
+ !ELSE
+ 
+ xyzzy.dll: $(DLL_OBJS)
+ 	link $(DLL_OBJS) -out:xyzzy.dll /RELEASE /NODEFAULTLIB /INCREMENTAL:NO /PDB:NONE /RELEASE /NOLOGO -entry:_DllMainCRTStartup@12 -dll libcmt.lib kernel32.lib user32.lib
+ 
+ !ENDIF
+ 
+ $(OUTDIR)/xyzzy.lib: xyzzy.dll
+ 
+ $(OUTDIR)/hook.obj: hook.cc hook.h wm.h
+ 	$(CXX) $(CXXFLAGS) -c -Tphook.cc
+ 
  libxpi.lib: xpi.obj
  	lib -out:$@ xpi.obj
  
***************
*** 344,350 ****
  $(OUTDIR)/string.obj: sequence.h
  $(OUTDIR)/symtable.obj: symtable.h
  $(OUTDIR)/syntax.obj: syntaxinfo.h
! $(OUTDIR)/toplev.obj: ctl3d.h DnD.h environ.h fnkey.h pane.h
  $(OUTDIR)/vector.obj: sequence.h
  $(OUTDIR)/version.obj: version.h
  $(OUTDIR)/wstream.obj: StrBuf.h wstream.h
--- 368,374 ----
  $(OUTDIR)/string.obj: sequence.h
  $(OUTDIR)/symtable.obj: symtable.h
  $(OUTDIR)/syntax.obj: syntaxinfo.h
! $(OUTDIR)/toplev.obj: ctl3d.h DnD.h environ.h fnkey.h pane.h hook.h
  $(OUTDIR)/vector.obj: sequence.h
  $(OUTDIR)/version.obj: version.h
  $(OUTDIR)/wstream.obj: StrBuf.h wstream.h
diff -c -N xyzzy/src-orig/hook.cc xyzzy/src/hook.cc
*** xyzzy/src-orig/hook.cc	Thu Jan 01 09:00:00 1970
--- xyzzy/src/hook.cc	Tue Nov 16 19:47:35 1999
***************
*** 0 ****
--- 1,163 ----
+ #include "windows.h"
+ typedef unsigned int u_int;
+ #define _hook_cc_
+ #include "hook.h"
+ #include "wm.h"
+ 
+ 
+ struct HookList
+ {
+   DWORD thread_id;
+   HHOOK hhook;
+   HookList *next;
+   HookList(DWORD tid, HHOOK hh) : thread_id(tid), hhook(hh), next(NULL) { }
+ };
+ 
+ 
+ static HookList hook_list(0, NULL);
+ static bool ime_composition;
+ static bool is_menu;
+ __declspec(dllexport) HookData hook_data;
+ static LRESULT CALLBACK getMessageProc(int code, WPARAM wParam, LPARAM lParam);
+ 
+ 
+ static bool install_hook(HINSTANCE hinstDLL)
+ {
+   DWORD thread_id = GetCurrentThreadId();
+   HHOOK hhook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)getMessageProc,
+ 				 hinstDLL, thread_id);
+   if (!hhook)
+     return false;
+   
+   HookList *hl;
+   for (hl = &hook_list; hl->next; hl = hl->next)
+     ;
+   hl->next = new HookList(thread_id, hhook);
+   return true;
+ }
+ 
+ 
+ static bool uninstall_hook()
+ {
+   DWORD thread_id = GetCurrentThreadId();
+   HookList *hl;
+   for (hl = &hook_list; hl->next; hl = hl->next)
+   {
+     HookList *next = hl->next;
+     if (next->thread_id == thread_id)
+     {
+       bool result = !!UnhookWindowsHookEx(next->hhook);
+       hl->next = next->next;
+       delete next;
+       return result;
+     }
+   }
+   return false;
+ }
+ 
+ 
+ static HHOOK get_hhook()
+ {
+   DWORD thread_id = GetCurrentThreadId();
+   HookList *hl;
+   for (hl = &hook_list; hl->next; hl = hl->next)
+     if (hl->next->thread_id == thread_id)
+       return hl->next->hhook;
+   return NULL;
+ }
+ 
+ 
+ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
+ 		    LPVOID /* lpvReserved */)
+ {
+   switch (fdwReason)
+   {
+     case DLL_PROCESS_ATTACH:
+     case DLL_THREAD_ATTACH:
+       install_hook(hinstDLL);
+       break;
+     case DLL_PROCESS_DETACH:
+     case DLL_THREAD_DETACH:
+       uninstall_hook();
+       break;
+     default:
+       break;
+   }
+   return TRUE;
+ }
+ 
+ 
+ void hotkey_on()
+ {
+   PostThreadMessage(hook_data.quit_thread_id,
+ 		    WM_PRIVATE_REGISTER_HOTKEY, 0, 0);
+ }
+ 
+ 
+ void hotkey_off()
+ {
+   PostThreadMessage(hook_data.quit_thread_id,
+ 		    WM_PRIVATE_UNREGISTER_HOTKEY, 0, 0);
+ }
+ 
+ 
+ static LRESULT CALLBACK getMessageProc(int code, WPARAM wParam, LPARAM lParam)
+ {
+   MSG &msg = *(MSG *)lParam;
+ 
+   if (code == HC_ACTION &&
+       (wParam & (PM_NOREMOVE | PM_REMOVE)) == PM_REMOVE)
+   {
+     switch (msg.message)
+     {
+       case WM_IME_ENDCOMPOSITION:
+ 	ime_composition = false;
+ 	hotkey_on();
+ 	break;
+ 	
+       case WM_IME_STARTCOMPOSITION:
+ 	ime_composition = true;
+ 	hotkey_off();
+ 	break;
+ 
+       default:
+ 	if (!ime_composition)
+ 	  break;
+ 	switch (msg.message)
+ 	{
+ 	  case WM_KEYDOWN:
+ 	  case WM_SYSKEYDOWN:
+ 	    switch (msg.wParam)
+ 	    {
+ 	      case VK_PROCESSKEY:
+ 	      case VK_CONTROL: case VK_LCONTROL: case VK_RCONTROL:
+ 	      case VK_SHIFT: case VK_LSHIFT: case VK_RSHIFT:
+ 	      case VK_MENU: case VK_LMENU: case VK_RMENU:
+ 	      case VK_LWIN: case VK_RWIN:
+ 		break;
+ 	      default:
+ 		hotkey_on();
+ 		break;
+ 	    }
+ 	    break;
+ 	      
+ 	  case WM_KEYUP:
+ 	  case WM_SYSKEYUP:
+ 	    if (!is_menu)
+ 	      hotkey_off();
+ 	    break;
+ 	    
+ 	  case WM_ENTERMENULOOP:
+ 	    is_menu = true;
+ 	    hotkey_on();
+ 	    break;
+ 	    
+ 	  case WM_EXITMENULOOP:
+ 	    is_menu = false;
+ 	    hotkey_off();
+ 	}
+ 	break;
+     }
+   }
+   return CallNextHookEx(get_hhook(), code, wParam, lParam);
+ }
diff -c -N xyzzy/src-orig/hook.h xyzzy/src/hook.h
*** xyzzy/src-orig/hook.h	Thu Jan 01 09:00:00 1970
--- xyzzy/src/hook.h	Tue Nov 16 19:48:03 1999
***************
*** 0 ****
--- 1,13 ----
+ #ifndef _hook_h_
+ #define _hook_h_
+ 
+ struct HookData
+ {
+   u_int quit_thread_id;
+ };
+ 
+ #ifndef _hook_cc_
+ __declspec(dllimport) HookData hook_data;
+ #endif // _hook_cc_
+ 
+ #endif // _hook_h_
diff -c -N xyzzy/src-orig/toplev.cc xyzzy/src/toplev.cc
*** xyzzy/src-orig/toplev.cc	Tue Nov 16 02:33:13 1999
--- xyzzy/src/toplev.cc	Tue Nov 16 20:05:06 1999
***************
*** 5,10 ****
--- 5,11 ----
  #include "environ.h"
  #include "fnkey.h"
  #include "pane.h"
+ #include "hook.h"
  
  #define DnDTEST
  #include "DnD.h"
***************
*** 106,111 ****
--- 107,117 ----
                }
              break;
  
+ 	  case WM_PRIVATE_UNREGISTER_HOTKEY:
+ 	    if (fg)
+ 	      UnregisterHotKey (0, 1);
+ 	    break;
+ 
            case WM_HOTKEY:
              if (!app.f_protect_quit)
                {
***************
*** 125,130 ****
--- 131,137 ----
    u_long h = _beginthreadex (0, 0, quit_thread_entry, &id, 0, &app.quit_thread_id);
    if (h == -1)
      return 0;
+   ::hook_data.quit_thread_id = app.quit_thread_id;
  
    int result = 0;
    MSG msg;
diff -c -N xyzzy/src-orig/wm.h xyzzy/src/wm.h
*** xyzzy/src-orig/wm.h	Sat Oct 16 18:47:08 1999
--- xyzzy/src/wm.h	Tue Nov 16 17:47:45 1999
***************
*** 21,26 ****
--- 21,27 ----
    WM_PRIVATE_IME_MODE,
    WM_PRIVATE_CALL_MENU,
    WM_PRIVATE_REGISTER_HOTKEY,
+   WM_PRIVATE_UNREGISTER_HOTKEY,
  };
  
  #endif

Index Home