30 #include <tqpainter.h>
31 #include <tqvaluelist.h>
34 #include <twinmodule.h>
37 #include <kstringhandler.h>
40 #include <tdeapplication.h>
42 #include <dcopclient.h>
45 #include "twindowlistmenu.h"
46 #include "twindowlistmenu.moc"
48 static TQCString twinName() {
50 int screen_number = DefaultScreen(tqt_xdisplay());
51 if (screen_number == 0)
54 appname.sprintf(
"twin-screen-%d", screen_number);
61 class NameSortedInfoList :
public TQPtrList<KWin::WindowInfo>
64 NameSortedInfoList() { setAutoDelete(
true); }
65 ~NameSortedInfoList() {}
68 int compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 );
71 int NameSortedInfoList::compareItems( TQPtrCollection::Item s1, TQPtrCollection::Item s2 )
75 TQString title1, title2;
80 return title1.compare(title2);
85 KWindowListMenu::KWindowListMenu(TQWidget *parent,
const char *name)
90 connect(
this, TQ_SIGNAL(activated(
int)), TQ_SLOT(slotExec(
int)));
93 KWindowListMenu::~KWindowListMenu()
98 static bool standaloneDialog(
const KWin::WindowInfo* info,
const NameSortedInfoList& list )
105 for( TQPtrListIterator< KWin::WindowInfo > it( list );
106 it.current() != NULL;
108 if( (*it)->groupLeader() == group )
113 void KWindowListMenu::init()
118 int nd = twin_module->numberOfDesktops();
119 int cd = twin_module->currentDesktop();
120 WId active_window = twin_module->activeWindow();
124 int maxwidth = kapp->desktop()->screenGeometry(
this ).width() / 2 - 100;
129 int unclutter = insertItem( i18n(
"Unclutter Windows"),
130 this, TQ_SLOT( slotUnclutterWindows() ) );
131 int cascade = insertItem( i18n(
"Cascade Windows"),
132 this, TQ_SLOT( slotCascadeWindows() ) );
141 TQValueList<KWin::WindowInfo> windows;
142 for (TQValueList<WId>::ConstIterator it = twin_module->windows().begin();
143 it != twin_module->windows().end(); ++it) {
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 );
151 if (!active_window && d == cd)
152 setItemChecked(1000 + d,
true);
154 NameSortedInfoList list;
155 list.setAutoDelete(
true);
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())) {
162 NET::WMVisibleName | NET::WMState | NET::XAWMState | NET::WMWindowType,
163 NET::WM2GroupLeader | NET::WM2TransientFor ));
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) ) {
180 if ( items == 1 && nd > 1 )
182 if( !on_all_desktops )
183 insertTitle(twin_module->desktopName( d ), 1000 + d);
185 insertTitle(i18n(
"On All Desktops"), 2000 );
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);
199 setItemEnabled(unclutter, items > 0);
200 setItemEnabled(cascade, items > 0);
213 setItemEnabled(insertItem(i18n(
"No Windows")),
false);
217 void KWindowListMenu::slotExec(
int id)
231 void KWindowListMenu::selectActiveWindow()
233 for(
unsigned int i = 0;
236 if( isItemChecked( idAt( i )))
243 void KWindowListMenu::slotUnclutterWindows()
245 kapp->dcopClient()->send(twinName(),
"KWinInterface",
"unclutterDesktop()", TQString(
""));
248 void KWindowListMenu::slotCascadeWindows()
250 kapp->dcopClient()->send(twinName(),
"KWinInterface",
"cascadeDesktop()", TQString(
""));
253 void KWindowListMenu::virtual_hook(
int id,
void* data )
254 { TDEPopupMenu::virtual_hook(
id, data ); }
static TQString cPixelSqueeze(const TQString &name, const TQFontMetrics &fontMetrics, uint maxPixels)
NET::WindowType windowType(int supported_types) const
TQString visibleNameWithState() const
unsigned long state() const
static void setCurrentDesktop(int desktop)
static void forceActiveWindow(WId win, long time=0)
static WindowInfo windowInfo(WId win, unsigned long properties=0, unsigned long properties2=0)
static TQPixmap icon(WId win, int width=-1, int height=-1, bool scale=false)
TDEAction * clear(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name)
Clear the content of the focus widget.
TQString name(StdAccel id)