/* This file is part of the KDE libraries Copyright (C) 1999 Matthias Ettrich (ettrich@kde.org) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KWIN_H #define KWIN_H #include #include #include #include #include "tdelibs_export.h" #ifdef Q_OS_UNIX #include class NETWinInfo; /** * Convenience access to certain properties and features of the * window manager. * * This class is not supposed to be instantiated. It exists mostly as * a namespace for the static member functions. * * In KDE 2 and KDE 3, communication with the windowmanager is done with the * NET-protocol, a common window manager specification designed by * various authors of X11 window managers (including those of the KDE * project). The full specification can be found at * www.freedesktop.org/standards/wm-spec . * * To access features of the NET-protocol, use the classes NETRootInfo * and NETWinInfo. * * The purpose of this class is to to provide easy access to the * most-commonly used NET-features with a simpler, KDEish interface. * * In addition, it encapsulates KDE functionality not yet provided by * the NET hints. Currently that is invokeContextHelp() and * setSystemTrayWindowFor() only. * * @short Class for interaction with the window manager. * @see NET * @see NetWinInfo * @author Matthias Ettrich (ettrich@kde.org) */ class TDECORE_EXPORT KWin { public: /** * Requests that window @p win is activated. * * There are two ways how to activate a window, by calling * activateWindow() and forceActiveWindow(). Generally, * applications shouldn't make attempts to explicitly activate * their windows, and instead let the user to activate them. * In the special cases where this may be needed, applications * should use activateWindow(). Window manager may consider whether * this request wouldn't result in focus stealing, which * would be obtrusive, and may refuse the request. * * The usage of forceActiveWindow() is meant only for pagers * and similar tools, which represent direct user actions * related to window manipulation. * Except for rare cases, this request will be always honored, * and normal applications are forbidden to use it. * * In case of problems, consult the KWin README in the tdebase * package (tdebase/twin/README), or ask on the twin@kde.org * mailing list. * * @param win the id of the window to make active * @param time X server timestamp of the user activity that * caused this request * @since 3.2 */ static void activateWindow( WId win, long time = 0 ); /** * Sets window @p win to be the active window. Note that this * should be called only in special cases, applications * shouldn't force themselves or other windows to be the active * window. Generally, this call should used only by pagers * and similar tools. See the explanation in description * of activateWindow(). * * @param win the id of the window to make active * @param time X server timestamp of the user activity that * caused this request * * @since 3.2 */ static void forceActiveWindow( WId win, long time = 0 ); /** * @deprecated Consider using activateWindow(), use forceActiveWindow() * only if necessary. */ static void setActiveWindow( WId win ) KDE_DEPRECATED; /** * When application finishes some operation and wants to notify * the user about it, it can call demandAttention(). Instead * of activating the window, which could be obtrusive, the window * will be marked specially as demanding user's attention. * See also explanation in description of activateWindow(). * * Note that it's usually better to use KNotifyClient. * * @since 3.2 */ static void demandAttention( WId win, bool set = true ); /** * Sets user timestamp @p time on window @p win. The timestamp * is expressed as XServer time. If a window * is shown with user timestamp older than the time of the last * user action, it won't be activated after being shown. * The most common case is the special value 0 which means * not to activate the window after being shown. * * @since 3.2 */ static void setUserTime( WId win, long time ); /** * Invokes interactive context help. */ static void invokeContextHelp(); /** * Sets the parent window of @p subwindow to be @p mainwindow. * This overrides the parent set the usual way as the TQWidget parent, * but only for the window manager - e.g. stacking order and window grouping * will be affected, but features like automatic deletion of children * when the parent is deleted are unaffected and normally use * the TQWidget parent. * * This function should be used before a dialog is shown for a window * that belongs to another application. * * @since 3.4 */ static void setMainWindow( TQWidget* subwindow, WId mainwindow ); /** * Makes @p trayWin a system tray window for @p forWin. * * A system tray window serves as an icon replacement. It's * displayed inside the panel's system tray. * @param trayWin the id of the system tray window * @param forWin the id of the window represented by the system * tray window */ static void setSystemTrayWindowFor( WId trayWin, WId forWin ); class WindowInfo; class WindowInfoPrivate; /** * Returns information about window @p win. It is recommended to check * whether the returned info is valid by calling the valid() method. * @param win the id of the window * @param properties all properties that should be retrieved (see NET::Property * enum for details) - passing 0 means all properties. Unlisted properties * cause related information to be invalid in the returned data, but * make this function faster when not all data is needed. * @param properties2 additional properties (see NET::Property2 enum). Note that * specifying 0 means no properties, not all. * @return the window information * @since 3.2 */ static WindowInfo windowInfo( WId win, unsigned long properties = 0, unsigned long properties2 = 0 ); /** * Returns the WM_TRANSIENT_FOR property for the given window, i.e. the mainwindow * for this window. * * @param window the id of the window * @since 3.2 */ static WId transientFor( WId window ); /** * Returns the leader window for the group the given window is in, if any. * @param window the id of the window * @since 3.2 */ static WId groupLeader( WId window ); /** * Returns an icon for window @p win. * * If @p width and @p height are specified, the best icon for the requested * size is returned. * * If @p scale is true, the icon is smooth-scaled to have exactly * the requested size. * * @param win the id of the window * @param width the desired width, or -1 * @param height the desired height, or -1 * @param scale if true the icon will be scaled to the desired size. Otherwise the * icon will not be modified. * @return the icon of the window */ static TQPixmap icon( WId win, int width = -1, int height = -1, bool scale = false ); /** * Masks specifying from which sources to read an icon. They are tried from the best * until an icon is found. * @li NETWM from property from the window manager specification * @li WMHints from WMHints property * @li ClassHint load icon after getting name from the classhint * @li XApp load the standard X icon (last fallback) */ enum IconSource { NETWM = 1, //!< read from property from the window manager specification WMHints = 2, //!< read from WMHints property ClassHint = 4, //!< load icon after getting name from the classhint XApp = 8 //! appended * when there are two or more windows with the same name). * Requires NET::WMVisibleName passed to KWin::windowInfo(). */ TQString visibleName() const; /** * Returns a visible name with state. * * This is a simple convenience function that returns the * visible name but with parentheses around minimized windows. * Requires NET::WMVisibleName, NET::WMState and NET::XAWMState passed * to KWin::windowInfo(). * @return the window name with state */ TQString visibleNameWithState() const; /** * Returns the name of the window, as specified by the application, without * any modifications. You should often use visibleName() instead. * Requires NET::WMName passed to KWin::windowInfo(). */ TQString name() const; /** * Returns the visible name of the window that should be shown in taskbar * and all other "iconic" representations of the window. Note that this * has nothing to do with normal icons. * Requires NET::WMVisibleIconName passed to KWin::windowInfo(). */ TQString visibleIconName() const; /** * Returns a visible name with state. * * This is a simple convenience function that returns the * visible iconic name but with parentheses around minimized windows. * Note that this has nothing to do with normal icons. * Requires NET::WMVisibleIconName, NET::WMState and NET::XAWMState passed * to KWin::windowInfo(). * @return the window iconic name with state */ TQString visibleIconNameWithState() const; /** * Returns the name of the window that should be shown in taskbar and all other * "iconic" representations of the window. Note that this has nothing to do * with normal icons. * Requires NET::WMIconName passed to KWin::windowInfo(). */ TQString iconName() const; /** * Returns true if the window is on the currently active virtual desktop. * Requires NET::WMDesktop passed to KWin::windowInfo(). */ bool isOnCurrentDesktop() const; /** * Returns true if the window is on the given virtual desktop. * Requires NET::WMDesktop passed to KWin::windowInfo(). */ bool isOnDesktop( int desktop ) const; /** * Returns true if the window is on all desktops * (equal to desktop()==NET::OnAllDesktops). * Requires NET::WMDesktop passed to KWin::windowInfo(). */ bool onAllDesktops() const; /** * Returns the virtual desktop this window is on (NET::OnAllDesktops if the window * is on all desktops). You should prefer using isOnDesktop(). * Requires NET::WMDesktop passed to KWin::windowInfo(). */ int desktop() const; /** * Returns the position and size of the window contents. * Requires NET::WMGeometry passed to KWin::windowInfo(). */ TQRect geometry() const; /** * Returns the frame geometry of the window, i.e. including the window decoration. * Requires NET::WMKDEFrameStrut passed to KWin::windowInfo(). */ TQRect frameGeometry() const; /** * Returns the WM_TRANSIENT_FOR property for the window, i.e. the mainwindow * for this window. * Requires NET::WM2TransientFor passed to KWin::windowInfo(). */ WId transientFor() const; /** * Returns the leader window for the group the window is in, if any. * Requires NET::WM2GroupLeader passed to KWin::windowInfo(). */ WId groupLeader() const; /** * Returns the class component of the window class for the window * (i.e. WM_CLASS property). * Requires NET::WM2WindowClass passed to KWin::windowInfo(). * @since 3.3 */ TQCString windowClassClass() const; /** * Returns the name component of the window class for the window * (i.e. WM_CLASS property). * Requires NET::WM2WindowClass passed to KWin::windowInfo(). * @since 3.3 */ TQCString windowClassName() const; /** * Returns the window role for the window (i.e. WM_WINDOW_ROLE property). * Requires NET::WM2WindowRole passed to KWin::windowInfo(). * @since 3.3 */ TQCString windowRole() const; /** * Returns the client machine for the window (i.e. WM_CLIENT_MACHINE property). * Requires NET::WMClientMachine passed to KWin::windowInfo(). * @since 3.3 */ TQCString clientMachine() const; /** * Returns true if the given action is currently supported for the window * by the window manager. * Requires NET::WM2AllowedActions passed to KWin::windowInfo(). */ bool actionSupported( NET::Action action ) const; WindowInfo( const WindowInfo& ); WindowInfo& operator=( const WindowInfo& ); private: WindowInfoPrivate* d; }; #endif //Q_OS_UNIX #endif