• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

  • tdeui
twindowlistmenu.cpp
1/*****************************************************************
2
3Copyright (c) 2000 Matthias Elter <elter@kde.org>
4 Matthias Ettrich <ettrich@kde.org>
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in
14all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23******************************************************************/
24
25#include <tqglobal.h>
26
27#ifdef TQ_WS_X11
28
29#include "config.h"
30#include <tqpainter.h>
31#include <tqvaluelist.h>
32
33#include <twin.h>
34#include <twinmodule.h>
35
36#include <tdelocale.h>
37#include <kstringhandler.h>
38
39#include <netwm.h>
40#include <tdeapplication.h>
41#include <tdestyle.h>
42#include <dcopclient.h>
43
44#undef Bool
45#include "twindowlistmenu.h"
46#include "twindowlistmenu.moc"
47
48static TQCString twinName() {
49 TQCString appname;
50 int screen_number = DefaultScreen(tqt_xdisplay());
51 if (screen_number == 0)
52 appname = "twin";
53 else
54 appname.sprintf("twin-screen-%d", screen_number);
55 return appname;
56}
57
58// helper class
59namespace
60{
61class NameSortedInfoList : public TQPtrList<KWin::WindowInfo>
62{
63public:
64 NameSortedInfoList() { setAutoDelete(true); }
65 ~NameSortedInfoList() {}
66
67private:
68 int compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 );
69};
70
71int NameSortedInfoList::compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 )
72{
73 KWin::WindowInfo *i1 = static_cast<KWin::WindowInfo *>(s1);
74 KWin::WindowInfo *i2 = static_cast<KWin::WindowInfo *>(s2);
75 TQString title1, title2;
76 if (i1)
77 title1 = i1->visibleNameWithState().lower();
78 if (i2)
79 title2 = i2->visibleNameWithState().lower();
80 return title1.compare(title2);
81}
82
83} // namespace
84
85KWindowListMenu::KWindowListMenu(TQWidget *parent, const char *name)
86 : TDEPopupMenu(parent, name)
87{
88 twin_module = new KWinModule(this);
89
90 connect(this, TQ_SIGNAL(activated(int)), TQ_SLOT(slotExec(int)));
91}
92
93KWindowListMenu::~KWindowListMenu()
94{
95
96}
97
98static bool standaloneDialog( const KWin::WindowInfo* info, const NameSortedInfoList& list )
99{
100 WId group = info->groupLeader();
101 if( group == 0 )
102 {
103 return info->transientFor() == tqt_xrootwin();
104 }
105 for( TQPtrListIterator< KWin::WindowInfo > it( list );
106 it.current() != NULL;
107 ++it )
108 if( (*it)->groupLeader() == group )
109 return false;
110 return true;
111}
112
113void KWindowListMenu::init()
114{
115 int i, d;
116 i = 0;
117
118 int nd = twin_module->numberOfDesktops();
119 int cd = twin_module->currentDesktop();
120 WId active_window = twin_module->activeWindow();
121
122 // Make sure the popup is not too wide, otherwise clicking in the middle of kdesktop
123 // wouldn't leave any place for the popup, and release would activate some menu entry.
124 int maxwidth = tdeApp->desktop()->screenGeometry( this ).width() / 2 - 100;
125
126 clear();
127 map.clear();
128
129 int unclutter = insertItem( i18n("Unclutter Windows"),
130 this, TQ_SLOT( slotUnclutterWindows() ) );
131 int cascade = insertItem( i18n("Cascade Windows"),
132 this, TQ_SLOT( slotCascadeWindows() ) );
133
134 // if we only have one desktop we won't be showing titles, so put a separator in
135 if (nd == 1)
136 {
137 insertSeparator();
138 }
139
140
141 TQValueList<KWin::WindowInfo> windows;
142 for (TQValueList<WId>::ConstIterator it = twin_module->windows().begin();
143 it != twin_module->windows().end(); ++it) {
144 windows.append( KWin::windowInfo( *it, NET::WMDesktop ));
145 }
146 bool show_all_desktops_group = ( nd > 1 );
147 for (d = 1; d <= nd + (show_all_desktops_group ? 1 : 0); d++) {
148 bool on_all_desktops = ( d > nd );
149 int items = 0;
150
151 if (!active_window && d == cd)
152 setItemChecked(1000 + d, true);
153
154 NameSortedInfoList list;
155 list.setAutoDelete(true);
156
157 for (TQValueList<KWin::WindowInfo>::ConstIterator it = windows.begin();
158 it != windows.end(); ++it) {
159 if (((*it).desktop() == d) || (on_all_desktops && (*it).onAllDesktops())
160 || (!show_all_desktops_group && (*it).onAllDesktops())) {
161 list.inSort(new KWin::WindowInfo( (*it).win(),
162 NET::WMVisibleName | NET::WMState | NET::XAWMState | NET::WMWindowType,
163 NET::WM2GroupLeader | NET::WM2TransientFor ));
164 }
165 }
166
167 for (KWin::WindowInfo* info = list.first(); info; info = list.next(), ++i)
168 {
169 TQString itemText = KStringHandler::cPixelSqueeze(info->visibleNameWithState(), fontMetrics(), maxwidth);
170 NET::WindowType windowType = info->windowType( NET::NormalMask | NET::DesktopMask
171 | NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask
172 | NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask );
173 if ( (windowType == NET::Normal || windowType == NET::Unknown
174 || (windowType == NET::Dialog && standaloneDialog( info, list )))
175 && !(info->state() & NET::SkipTaskbar) ) {
176 TQPixmap pm = KWin::icon(info->win(), 16, 16, true );
177 items++;
178
179 // ok, we have items on this desktop, let's show the title
180 if ( items == 1 && nd > 1 )
181 {
182 if( !on_all_desktops )
183 insertTitle(twin_module->desktopName( d ), 1000 + d);
184 else
185 insertTitle(i18n("On All Desktops"), 2000 );
186 }
187
188 // Avoid creating unwanted accelerators.
189 itemText.replace('&', TQString::fromLatin1("&&"));
190 insertItem( pm, itemText, i);
191 map.insert(i, info->win());
192 if (info->win() == active_window)
193 setItemChecked(i, true);
194 }
195 }
196
197 if (d == cd)
198 {
199 setItemEnabled(unclutter, items > 0);
200 setItemEnabled(cascade, items > 0);
201 }
202 }
203
204 // no windows?
205 if (i == 0)
206 {
207 if (nd > 1)
208 {
209 // because we don't have any titles, nor a separator
210 insertSeparator();
211 }
212
213 setItemEnabled(insertItem(i18n("No Windows")), false);
214 }
215}
216
217void KWindowListMenu::slotExec(int id)
218{
219 if (id == 2000)
220 ; // do nothing
221 else if (id > 1000)
222 KWin::setCurrentDesktop(id - 1000);
223 else if ( id >= 0 )
224 KWin::forceActiveWindow(map[id]);
225}
226
227// This popup is much more useful from keyboard if it has the active
228// window active by default - however, TQPopupMenu tries hard to resist.
229// TQPopupMenu::popup() resets the active item, so this needs to be
230// called after popup().
231void KWindowListMenu::selectActiveWindow()
232{
233 for( unsigned int i = 0;
234 i < count();
235 ++i )
236 if( isItemChecked( idAt( i )))
237 {
238 setActiveItem( i );
239 break;
240 }
241}
242
243void KWindowListMenu::slotUnclutterWindows()
244{
245 tdeApp->dcopClient()->send(twinName(), "KWinInterface", "unclutterDesktop()", TQString(""));
246}
247
248void KWindowListMenu::slotCascadeWindows()
249{
250 tdeApp->dcopClient()->send(twinName(), "KWinInterface", "cascadeDesktop()", TQString(""));
251}
252
253void KWindowListMenu::virtual_hook( int id, void* data )
254{ TDEPopupMenu::virtual_hook( id, data ); }
255
256#endif // TQ_WS_X11
257
KStringHandler::cPixelSqueeze
static TQString cPixelSqueeze(const TQString &name, const TQFontMetrics &fontMetrics, uint maxPixels)
KWinModule
KWin::WindowInfo
KWin::WindowInfo::windowType
NET::WindowType windowType(int supported_types) const
KWin::WindowInfo::transientFor
WId transientFor() const
KWin::WindowInfo::win
WId win() const
KWin::WindowInfo::groupLeader
WId groupLeader() const
KWin::WindowInfo::visibleNameWithState
TQString visibleNameWithState() const
KWin::WindowInfo::state
unsigned long state() const
KWin::setCurrentDesktop
static void setCurrentDesktop(int desktop)
KWin::forceActiveWindow
static void forceActiveWindow(WId win, long time=0)
KWin::windowInfo
static WindowInfo windowInfo(WId win, unsigned long properties=0, unsigned long properties2=0)
KWin::icon
static TQPixmap icon(WId win, int width=-1, int height=-1, bool scale=false)
NET::WindowType
WindowType
TDEPopupMenu
A menu with title items.
Definition: tdepopupmenu.h:123
KStdAction::clear
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name)
Clear the content of the focus widget.
Definition: kstdaction.cpp:176
TDEStdAccel::name
TQString name(StdAccel id)
tdelocale.h

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.9.4
This website is maintained by Timothy Pearson.