/// <summary> /// Refresh language text. /// </summary> public void RefreshLang() { uint cLid = Locales.GetCurrentLocale(); if (DisplayFlag && MMain.mahou.DiffAppearenceForLayouts) { if (cLid == MahouUI.MAIN_LAYOUT1 && MMain.mahou.Layout1TText.Length < 2) { lbLang.Text = MMain.mahou.Layout1TText; } else if (cLid == MahouUI.MAIN_LAYOUT2 && MMain.mahou.Layout2TText.Length < 2) { lbLang.Text = MMain.mahou.Layout2TText; } Empty = (MMain.mahou.DiffAppearenceForLayouts && lbLang.Text == " "); } if (!Visible || Empty) { return; } if (cLid == 0) { cLid = MahouUI.currentLayout; } if (MMain.mahou.OneLayout) { cLid = MahouUI.GlobalLayout; } if (MMain.mahou.LDCaretTransparentBack_temp && caretDisplay) { transparentBG = true; } else if (MMain.mahou.LDMouseTransparentBack_temp && mouseDisplay) { transparentBG = true; } else { transparentBG = false; } var notTwo = false; if ((cLid & 0xffff) > 0) { var clangname = new System.Globalization.CultureInfo((int)(cLid & 0xffff)); if (MMain.mahou.DiffAppearenceForLayouts && !DisplayFlag) { if (cLid == MahouUI.MAIN_LAYOUT1) { ChangeColors(MMain.mahou.Layout1Font_temp, MMain.mahou.Layout1Fore_temp, MMain.mahou.Layout1Back_temp, MMain.mahou.Layout1TransparentBack_temp); ChangeSize(MMain.mahou.Layout1Height_temp, MMain.mahou.Layout1Width_temp); ChangeLD(MMain.mahou.Layout1TText); } else if (cLid == MahouUI.MAIN_LAYOUT2) { ChangeColors(MMain.mahou.Layout2Font_temp, MMain.mahou.Layout2Fore_temp, MMain.mahou.Layout2Back_temp, MMain.mahou.Layout2TransparentBack_temp); ChangeSize(MMain.mahou.Layout2Height_temp, MMain.mahou.Layout2Width_temp); ChangeLD(MMain.mahou.Layout2TText); } else { notTwo = true; } } else { notTwo = true; } if (notTwo) { if (mouseDisplay) { ChangeColors(MMain.mahou.LDMouseFont_temp, MMain.mahou.LDMouseFore_temp, MMain.mahou.LDMouseBack_temp, MMain.mahou.LDMouseTransparentBack_temp); ChangeSize(MMain.mahou.LDMouseHeight_temp, MMain.mahou.LDMouseWidth_temp); } if (caretDisplay) { ChangeColors(MMain.mahou.LDCaretFont_temp, MMain.mahou.LDCaretFore_temp, MMain.mahou.LDCaretBack_temp, MMain.mahou.LDCaretTransparentBack_temp); ChangeSize(MMain.mahou.LDCaretHeight_temp, MMain.mahou.LDCaretWidth_temp); } ChangeLD(clangname.ThreeLetterISOLanguageName.Substring(0, 1).ToUpper() + clangname.ThreeLetterISOLanguageName.Substring(1)); } if (!MMain.mahou.DiffAppearenceForLayouts || lbLang.Text == "") { ChangeLD(clangname.ThreeLetterISOLanguageName.Substring(0, 1).ToUpper() + clangname.ThreeLetterISOLanguageName.Substring(1)); } if (transparentBG) { TransparencyKey = BackColor = lbLang.BackColor = pct_UpperArrow.BackColor = Color.Pink; } if (lastTransparentBG != transparentBG) { SetVisInvis(); } lastTransparentBG = transparentBG; if ((caretDisplay && !MahouUI.caretLTUpperArrow) || (mouseDisplay && !MahouUI.mouseLTUpperArrow) || onInit) { ReSize(); onInit = false; } } else { Logging.Log("Language tooltip text NOT changed, locale id = [" + cLid + "].", 2); } }
public static void Init() { if (running) { bool exist = true; if (Environment.Is64BitOperatingSystem) { if (Process.GetProcessesByName("jkl").Length > 0) { Logging.Log("[JKL] > JKL already running."); } else { exist = false; } } else { if (Process.GetProcessesByName("jklx86").Length > 0) { Logging.Log("[JKL] > JKLx86 already running."); } else { exist = false; } } if (!exist) { Logging.Log("[JKL] > JKL seems closed, restarting..."); running = false; } } if (HWND == IntPtr.Zero) { Logging.Log("[JKL] > Initializing JKL HWND server..."); WNDPROC_DELEGATE = jklWndProc; var wnd_class = new WinAPI.WNDCLASS(); wnd_class.lpszClassName = "_XHIDDEN_HWND_SERVER"; wnd_class.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(WNDPROC_DELEGATE); UInt16 cls_reg = WinAPI.RegisterClassW(ref wnd_class); int last_error = Marshal.GetLastWin32Error(); if (cls_reg == 0 && last_error != 0) { Logging.Log("[JKL] > Could not register window class, for jkl Hidden Server, err: " + last_error, 1); } HWND = WinAPI.CreateWindowExW(0, "_XHIDDEN_HWND_SERVER", "_XHIDDEN_HWND_SERVER", 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } if (!running) { if (jklExist()) { if (Environment.Is64BitOperatingSystem) { Logging.Log("[JKL] > Starting jkl.exe..."); var jkl = new ProcessStartInfo(); jkl.UseShellExecute = true; jkl.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jkl.exe"); jkl.WorkingDirectory = Path.Combine(Path.GetTempPath()); Process.Start(jkl); } else { Logging.Log("[JKL] > Starting \"jklx86.exe -msg\"..."); var jkl = new ProcessStartInfo(); jkl.UseShellExecute = true; jkl.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "jklx86.exe"); jkl.Arguments = "-msg"; jkl.WorkingDirectory = Path.Combine(Path.GetTempPath()); Process.Start(jkl); } var umsgID = Path.Combine(Path.GetTempPath(), "umsg.id"); var tries = 0; while (!File.Exists(umsgID)) { Thread.Sleep(350); tries++; if (tries > 20) { Logging.Log("[JKL] > Error, umsg.id not found after 20 tries by 350 ms timeout.", 1); Destroy(); break; } } if (tries <= 20) { Logging.Log("[JKL] > umsg.id found, after " + tries + " tries * 350ms timeout."); Logging.Log("[JKL] > Retrieving umsg.id..."); jkluMSG = Convert.ToInt32(File.ReadAllText(umsgID)); File.Delete(umsgID); KMHook.DoLater(() => CycleAllLayouts(Locales.ActiveWindow()), 350); running = true; } } else { Logging.Log("[JKL] > " + jklInfoStr, 1); } Logging.Log("[JKL] > Init done, umsg: [" + jkluMSG + "], JKLXServ: [" + HWND + "]."); } }