Use 'gb_Library_set_include' for GTK3_CFLAGS
[LibreOffice.git] / vcl / unx / kde4 / VCLKDEApplication.cxx
blob78181b2a486c73a1f4760cfef58c3f8b98f70f97
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "VCLKDEApplication.hxx"
22 #include <QtGui/QClipboard>
23 #include <QtCore/QEvent>
25 #include "KDESalDisplay.hxx"
27 VCLKDEApplication::VCLKDEApplication() :
28 KApplication()
32 bool VCLKDEApplication::x11EventFilter(XEvent* ev)
34 //if we have a display and the display consumes the event
35 //do not process the event in qt
36 if (SalKDEDisplay::self() && SalKDEDisplay::self()->Dispatch(ev))
38 return true;
41 return false;
44 // various hacks to be performed before re-entering Qt's event loop
45 // because of showing a Qt dialog
46 void VCLKDEApplication::preDialogSetup()
48 // KFileDialog integration requires using event loop with QClipboard.
49 // Opening the KDE file dialog here can lead to QClipboard
50 // asking for clipboard contents. If LO core is the owner of the clipboard
51 // content, without event loop use this will block for 5 seconds and timeout,
52 // since the clipboard thread will not be able to acquire SolarMutex
53 // and thus won't be able to respond. If the event loops
54 // are properly integrated and QClipboard can use a nested event loop
55 // (see the KDE VCL plug), then this won't happen.
56 // We cannot simply release SolarMutex here, because the event loop started
57 // by the file dialog would also call back to LO code.
58 assert( QApplication::clipboard()->property( "useEventLoopWhenWaiting" ).toBool() );
61 // various hacks to be performed after a Qt dialog has been closed
62 void VCLKDEApplication::postDialogCleanup()
64 // HACK: KFileDialog uses KConfig("kdeglobals") for saving some settings
65 // (such as the auto-extension flag), but that doesn't update KGlobal::config()
66 // (which is probably a KDE bug), so force reading the new configuration,
67 // otherwise the next opening of the dialog would use the old settings.
68 KGlobal::config()->reparseConfiguration();
69 // HACK: If Qt owns clipboard or selection, give up on their ownership now. Otherwise
70 // LO core might ask for the contents, but it would block while doing so (i.e. it
71 // doesn't seem to have an equivalent of QClipboard's "useEventLoopWhenWaiting"),
72 // therefore QClipboard wouldn't be able to respond, and whole LO would block until
73 // a timeout. Given that Klipper is most probably running, giving up clipboard/selection
74 // ownership will not only avoid the blocking, but even pasting that content in LO
75 // will in fact work, if Klipper can handle it.
76 // Technically proper solution would be of course to allow Qt to process QClipboard
77 // events while LO waits for clipboard contents, or short-circuit to QClipboard somehow
78 // (it's a mystery why LO's clipboard handling has its own thread when whole LO can
79 // get blocked by both trying to send and receive clipboard contents anyway).
80 QClipboard* clipboard = QApplication::clipboard();
81 if( clipboard->ownsSelection())
82 clipboard->clear( QClipboard::Selection );
83 if( clipboard->ownsClipboard())
84 clipboard->clear();
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */