示例#1
0
        private static void FixClipThread()
        {
            try
            {
#if !KeePassUAP && !KeePassUWP
                const int msDelay = 250;

                string strTest = ClipboardU.GetText();
                if (strTest == null)
                {
                    return;                                 // No clipboard support
                }
                // Without XDoTool, the workaround would be applied to
                // all applications, which may corrupt the clipboard
                // when it doesn't contain simple text only;
                // https://sourceforge.net/p/keepass/bugs/1603/#a113
                strTest = (NativeLib.RunConsoleApp(AppXDoTool,
                                                   "help") ?? string.Empty).Trim();
                if (strTest.Length == 0)
                {
                    return;
                }

                Thread.Sleep(msDelay);

                string strLast = null;
                while (true)
                {
                    string str = ClipboardU.GetText();
                    if (str == null)
                    {
                        Debug.Assert(false);
                    }
                    else if (str != strLast)
                    {
                        if (NeedClipboardWorkaround())
                        {
                            ClipboardU.SetText(str, true);
                        }

                        strLast = str;
                    }

                    Thread.Sleep(msDelay);
                }
#endif
            }
            catch (ThreadAbortException)
            {
#if !KeePassUWP
                try { Thread.ResetAbort(); }
                catch (Exception) { Debug.Assert(false); }
#endif
            }
            catch (Exception) { Debug.Assert(false); }
            finally { g_thFixClip = null; }
        }
示例#2
0
        private static bool NeedClipboardWorkaround()
        {
            const bool bDef = true;

            try
            {
                string strHandle = (NativeLib.RunConsoleApp("xdotool",
                                                            "getactivewindow") ?? string.Empty).Trim();
                if (strHandle.Length == 0)
                {
                    return(bDef);
                }

                // IntPtr h = new IntPtr(long.Parse(strHandle));
                long.Parse(strHandle);                 // Validate

                // Detection of own windows based on Form.Handle
                // comparisons doesn't work reliably (Mono's handles
                // are usually off by 1)
                // Predicate<IntPtr> fOwnWindow = m_fOwnWindow;
                // if(fOwnWindow != null)
                // {
                //	if(fOwnWindow(h)) return true;
                // }
                // else { Debug.Assert(false); }

                string strWmClass = (NativeLib.RunConsoleApp("xprop",
                                                             "-id " + strHandle + " WM_CLASS") ?? string.Empty);

                if (strWmClass.IndexOf("\"" + PwDefs.ResClass + "\"",
                                       StrUtil.CaseIgnoreCmp) >= 0)
                {
                    return(true);
                }

                // Workaround for Remmina
                if (strWmClass.IndexOf("\"Remmina\"",
                                       StrUtil.CaseIgnoreCmp) >= 0)
                {
                    return(true);
                }

                return(false);
            }
            catch (ThreadAbortException) { throw; }
            catch (Exception) { Debug.Assert(false); }

            return(bDef);
        }
示例#3
0
        private static void FixClipThread()
        {
            try
            {
#if !KeePassUAP
                const string      strXSel = "xsel";
                const AppRunFlags rfW     = AppRunFlags.WaitForExit;

                string strLast = null;
                while (true)
                {
                    string str = NativeLib.RunConsoleApp(strXSel,
                                                         "--output --clipboard");
                    if (str == null)
                    {
                        return;                                 // 'xsel' not installed
                    }
                    if (str != strLast)
                    {
                        if (NeedClipboardWorkaround())
                        {
                            NativeLib.RunConsoleApp(strXSel,
                                                    "--input --clipboard", str, rfW);
                        }

                        strLast = str;
                    }

                    Thread.Sleep(250);
                }
#endif
            }
            catch (ThreadAbortException)
            {
                try { Thread.ResetAbort(); }
                catch (Exception) { Debug.Assert(false); }
            }
            catch (Exception) { Debug.Assert(false); }
            finally { m_thFixClip = null; }
        }
示例#4
0
        private static void FixClipThread()
        {
            try
            {
#if !KeePassUAP
                const string      strXSel  = "xsel";
                const string      strXSelR = "--output --clipboard";
                const string      strXSelW = "--input --clipboard --nodetach";
                const AppRunFlags rfW      = AppRunFlags.WaitForExit;
                const int         msDelay  = 250;

                // XSel is required
                string strTest = NativeLib.RunConsoleApp(strXSel, strXSelR);
                if (strTest == null)
                {
                    return;                                 // XSel not installed
                }
                // Without XDoTool, the workaround would be applied to
                // all applications, which may corrupt the clipboard
                // when it doesn't contain simple text only;
                // https://sourceforge.net/p/keepass/bugs/1603/#a113
                strTest = (NativeLib.RunConsoleApp(AppXDoTool,
                                                   "help") ?? string.Empty).Trim();
                if (strTest.Length == 0)
                {
                    return;
                }

                Thread.Sleep(msDelay);

                string strLast = null;
                while (true)
                {
                    string str = NativeLib.RunConsoleApp(strXSel, strXSelR);
                    if (str == null)
                    {
                        Debug.Assert(false);
                    }
                    else if (str != strLast)
                    {
                        if (NeedClipboardWorkaround())
                        {
                            // Use --nodetach to prevent clipboard corruption;
                            // https://sourceforge.net/p/keepass/bugs/1603/
                            NativeLib.RunConsoleApp(strXSel, strXSelW, str, rfW);
                        }

                        strLast = str;
                    }

                    Thread.Sleep(msDelay);
                }
#endif
            }
            catch (ThreadAbortException)
            {
                try { Thread.ResetAbort(); }
                catch (Exception) { Debug.Assert(false); }
            }
            catch (Exception) { Debug.Assert(false); }
            finally { g_thFixClip = null; }
        }