summaryrefslogtreecommitdiffstats
path: root/src/qtraylabel.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <[email protected]>2020-03-16 21:58:44 +0900
committerMichele Calgaro <[email protected]>2020-03-16 21:58:44 +0900
commitab3e99d8ee8ef5b53dcd1e6f90e3cdbbc08322e3 (patch)
treee622bfddde12ec89c8a84bfefec8dce7140109db /src/qtraylabel.cpp
parentd9e1d9fa71544a674d213117c0b675a0e874e556 (diff)
downloadtdedocker-ab3e99d8ee8ef5b53dcd1e6f90e3cdbbc08322e3.tar.gz
tdedocker-ab3e99d8ee8ef5b53dcd1e6f90e3cdbbc08322e3.zip
Conversion to TDE application.
Notable changes: 1) save/restore data are saved in TDE session files. 2) remove -a, -l options. Removed "Launch on startup" option. 3) docked application are restored automatically by the TDE session manager. After being restored, tdedocker will wait for 5 seconds to let the various applications be restored, then it will try to grab the required windows. 4) save/restore of docked applications is now working properly. 5) due to the way TDE manages command line options, at the moment additional parameters cannot be passed to the application to be docked. This will be address in a subsequent commit. Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'src/qtraylabel.cpp')
-rw-r--r--src/qtraylabel.cpp130
1 files changed, 64 insertions, 66 deletions
diff --git a/src/qtraylabel.cpp b/src/qtraylabel.cpp
index 38a8381..a74ba48 100644
--- a/src/qtraylabel.cpp
+++ b/src/qtraylabel.cpp
@@ -30,7 +30,7 @@
#include <tqfileinfo.h>
#include <tqapplication.h>
#include "trace.h"
-#include "qtraylabel.h"
+#include <tdeconfig.h>
#include <kiconloader.h>
#include <tdeglobal.h>
@@ -43,9 +43,10 @@
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
-
#include "util.h"
+#include "qtraylabel.h"
+
void TQTrayLabel::initialize(void)
{
mDocked = false;
@@ -82,7 +83,7 @@ const char *TQTrayLabel::me(void) const
{
static char temp[100];
snprintf(temp, sizeof(temp), "(%s,PID=%i,WID=0x%x)",
- mProgName[0].latin1(), mPid, (unsigned) mDockedWindow);
+ mProgName[0].local8Bit().data(), mPid, (unsigned) mDockedWindow);
return temp;
}
@@ -128,15 +129,15 @@ void TQTrayLabel::scanClients()
for(unsigned i=0; i<nchildren; i++)
{
Window w = XmuClientWindow(display, children[i]);
- TRACE("\t%s checking 0x%x", me(), (unsigned) w);
+ TRACE("\t%s checking(1) 0x%x", me(), (unsigned) w);
if (!isNormalWindow(display, w)) continue;
- if (analyzeWindow(display, w, mPid, ename.latin1()))
+ if (analyzeWindow(display, w, mPid, ename.local8Bit()))
{
- TRACE("\t%s SOULMATE FOUND", me());
+ TRACE("\t%s SOULMATE FOUND (1)", me());
setDockedWindow(w);
- break;
+ return;
}
- }
+ }
}
/*
@@ -222,8 +223,8 @@ void TQTrayLabel::dock(void)
{
TRACE("%s", me());
mDocked = true;
- if (mDockedWindow == None) return; // nothing to add
-
+ if (mDockedWindow == None) return; // nothing to add
+
if (mSysTray == None) // no system tray yet
{
TRACE("%s starting reality monitor", me());
@@ -243,7 +244,7 @@ void TQTrayLabel::dock(void)
Atom tray_atom =
XInternAtom(display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", False);
XChangeProperty(display, wid, tray_atom, XA_WINDOW, 32,
- PropModeReplace, (unsigned char *) &wid, 1);
+ PropModeReplace, (unsigned char *) &wid, 1);
// 3. All other KDEs
tray_atom = XInternAtom(display, "KWM_DOCKWINDOW", False);
@@ -254,8 +255,8 @@ void TQTrayLabel::dock(void)
handleTitleChange();
handleIconChange();
-
- if (mProgName.count() == 0) setAppName(mClass);
+
+ if (mProgName.count() == 0) setAppName(mClass);
/*
* For Gnome, a delay is required before we do a show (dont ask me why)
@@ -294,7 +295,7 @@ void TQTrayLabel::map(void)
TRACE("%s", me());
mWithdrawn = false;
if (mDockedWindow == None) return;
-
+
Display *display = TQPaintDevice::x11AppDisplay();
if (mDesktop == -1)
@@ -324,12 +325,12 @@ void TQTrayLabel::map(void)
}
XMapWindow(display, mDockedWindow);
- mSizeHint.flags = USPosition; // Obsolete ?
+ mSizeHint.flags = USPosition; // Obsolete ?
XSetWMNormalHints(display, mDockedWindow, &mSizeHint);
// make it the active window
long l[5] = { None, CurrentTime, None, 0, 0 };
sendMessage(display, tqt_xrootwin(), mDockedWindow, "_NET_ACTIVE_WINDOW", 32,
- SubstructureNotifyMask | SubstructureRedirectMask, l, sizeof(l));
+ SubstructureNotifyMask | SubstructureRedirectMask, l, sizeof(l));
// skipTaskbar modifies _NET_WM_STATE. Make sure we dont override WMs value
TQTimer::singleShot(230, this, SLOT(skipTaskbar()));
// disable docking when minized for some time (since we went to Iconic state)
@@ -346,7 +347,7 @@ void TQTrayLabel::withdraw(void)
Display *display = TQPaintDevice::x11AppDisplay();
int screen = DefaultScreen(display);
long dummy;
-
+
XGetWMNormalHints(display, mDockedWindow, &mSizeHint, &dummy);
/*
@@ -357,7 +358,7 @@ void TQTrayLabel::withdraw(void)
* state will remove us from the taskbar.
* Reference: ICCCM 4.1.4 Changing Window State
*/
- XIconifyWindow(display, mDockedWindow, screen); // good for effects too
+ XIconifyWindow(display, mDockedWindow, screen); // good for effects too
XUnmapWindow(display, mDockedWindow);
XUnmapEvent ev;
memset(&ev, 0, sizeof(ev));
@@ -389,8 +390,8 @@ void TQTrayLabel::skipTaskbar(void)
Atom _NET_WM_STATE = XInternAtom(display, "_NET_WM_STATE", True);
Atom skip_atom = XInternAtom(display, "_NET_WM_STATE_SKIP_TASKBAR", False);
int ret = XGetWindowProperty(display, mDockedWindow, _NET_WM_STATE, 0,
- 20, False, AnyPropertyType, &type, &format,
- &nitems, &left, (unsigned char **) &data);
+ 20, False, AnyPropertyType, &type, &format,
+ &nitems, &left, (unsigned char **) &data);
Atom *old_states = (Atom *) data;
bool append = true, replace = false;
@@ -406,7 +407,7 @@ void TQTrayLabel::skipTaskbar(void)
{
if (num_states < nitems)
{
- replace = true; // need to remove skip_atom
+ replace = true; // need to remove skip_atom
for (; num_states < nitems - 1; num_states++)
old_states[num_states] = old_states[num_states + 1];
}
@@ -442,6 +443,7 @@ void TQTrayLabel::setSkipTaskbar(bool skip)
void TQTrayLabel::close(void)
{
TRACE("%s", me());
+ undock();
Display *display = TQPaintDevice::x11AppDisplay();
long l[5] = { 0, 0, 0, 0, 0 };
map();
@@ -457,7 +459,7 @@ void TQTrayLabel::setTrayIcon(const TQString& icon)
{
mCustomIcon = icon;
if (TQPixmap(mCustomIcon).isNull()) mCustomIcon = TQString::null;
- TRACE("%s mCustomIcon=%s", me(), mCustomIcon.latin1());
+ TRACE("%s mCustomIcon=%s", me(), mCustomIcon.local8Bit());
updateIcon();
}
@@ -469,18 +471,17 @@ void TQTrayLabel::setTrayIcon(const TQString& icon)
*/
void TQTrayLabel::setDockedWindow(Window w)
{
- TRACE("%s %s reality monitor", me(),
+ TRACE("%s %s reality monitor", me(),
mDockedWindow==None ? "Starting" : "Stopping");
// Check if we are allowed to dock this window (allows custom rules)
if (w != None) mDockedWindow = canDockWindow(w) ? w : None;
else mDockedWindow = None;
- if (mDockedWindow == None) mRealityMonitor.start(500);
- else mRealityMonitor.stop();
+ if (mDockedWindow == None) mRealityMonitor.start(500); else mRealityMonitor.stop();
Display *d = TQPaintDevice::x11AppDisplay();
-
+
// Subscribe for window or root window events
if (w == None) subscribe(d, None, SubstructureNotifyMask, true);
else
@@ -488,10 +489,10 @@ void TQTrayLabel::setDockedWindow(Window w)
if (canUnsubscribeFromRoot())
subscribe(d, None, ~SubstructureNotifyMask, false);
else subscribe(d, None, SubstructureNotifyMask, true);
-
+
subscribe(d, w,
StructureNotifyMask | PropertyChangeMask |
- VisibilityChangeMask | FocusChangeMask,
+ VisibilityChangeMask | FocusChangeMask,
true);
}
@@ -515,8 +516,8 @@ void TQTrayLabel::setDockedWindow(Window w)
void TQTrayLabel::balloonText()
{
TRACE("%s BalloonText=%s ToolTipText=%s", me(),
- mBalloon->text().latin1(), TQToolTip::textFor(this).latin1());
-
+ mBalloon->text().local8Bit(), TQToolTip::textFor(this).local8Bit());
+
if (mBalloon->text() == TQToolTip::textFor(this)) return;
#if 0 // I_GOT_NETWM_BALLOONING_TO_WORK
// if you can get NET WM ballooning to work let me know
@@ -528,7 +529,7 @@ void TQTrayLabel::balloonText()
SubstructureNotifyMask | SubstructureRedirectMask,
l, sizeof(l));
int length = mTitle.length();
- const char *data = mTitle.latin1();
+ const char *data = mTitle.local8Bit();
while (length > 0)
{
sendMessage(display, mSystemTray, winId(), "_NET_SYSTEM_TRAY_MESSAGE_DATA", 8,
@@ -564,7 +565,7 @@ void TQTrayLabel::handleTitleChange(void)
XFetchName(display, mDockedWindow, &window_name);
mTitle = window_name;
- TRACE("%s has title [%s]", me(), mTitle.latin1());
+ TRACE("%s has title [%s]", me(), mTitle.local8Bit());
if (window_name) XFree(window_name);
XClassHint ch;
@@ -698,10 +699,10 @@ bool TQTrayLabel::x11EventFilter(XEvent *ev)
mWithdrawn = true;
unmapEvent();
}
- else if (event->type == FocusOut)
- {
- focusLostEvent();
- }
+ else if (event->type == FocusOut)
+ {
+ focusLostEvent();
+ }
return true; // Dont process this again
}
@@ -712,8 +713,8 @@ bool TQTrayLabel::x11EventFilter(XEvent *ev)
Display *display = TQPaintDevice::x11AppDisplay();
Window w = XmuClientWindow(display, ((XMapEvent *) event)->window);
if (!isNormalWindow(display, w)) return FALSE;
- if (!analyzeWindow(display, w, mPid,
- TQFileInfo(mProgName[0]).fileName().latin1())) return FALSE;
+ if (!analyzeWindow(display, w, mPid,
+ TQFileInfo(mProgName[0]).fileName().local8Bit())) return FALSE;
// All right. Lets dock this baby
setDockedWindow(w);
return true;
@@ -759,8 +760,8 @@ void TQTrayLabel::propertyChangeEvent(Atom property)
unsigned long nitems, after;
unsigned char *data = NULL;
int r = XGetWindowProperty(display, mDockedWindow, WM_STATE,
- 0, 1, False, AnyPropertyType, &type,
- &format, &nitems, &after, &data);
+ 0, 1, False, AnyPropertyType, &type,
+ &format, &nitems, &after, &data);
if ((r == Success) && data && (*(long *) data == IconicState))
{
@@ -771,40 +772,37 @@ void TQTrayLabel::propertyChangeEvent(Atom property)
}
// Session Management
-bool TQTrayLabel::saveState(TQSettings &settings)
+void TQTrayLabel::saveState(TDEConfig *config)
{
TRACE("%s saving state", me());
- settings.writeEntry("/Application", mProgName.join(" "));
- settings.writeEntry("/CustomIcon", mCustomIcon);
- settings.writeEntry("/BalloonTimeout", mBalloonTimeout);
- settings.writeEntry("/DockWhenMinimized", mDockWhenMinimized);
- settings.writeEntry("/SkipTaskbar", mSkippingTaskbar);
- settings.writeEntry("/Withdraw", mWithdrawn);
- return true;
+ config->writeEntry("Application", mProgName.join(" "));
+ config->writeEntry("BalloonTimeout", mBalloonTimeout);
+ config->writeEntry("CustomIcon", mCustomIcon);
+ config->writeEntry("DockWhenMinimized", mDockWhenMinimized);
+ config->writeEntry("SkipTaskbar", mSkippingTaskbar);
+ config->writeEntry("Withdraw", mWithdrawn);
}
-bool TQTrayLabel::restoreState(TQSettings &settings)
+bool TQTrayLabel::restoreState(TDEConfig *config)
{
TRACE("%s restoring state", me());
- mCustomIcon = settings.readEntry("/CustomIcon");
- setBalloonTimeout(settings.readNumEntry("/BalloonTimeout"));
- setDockWhenMinimized(settings.readBoolEntry("/DockWhenMinimized"));
- setSkipTaskbar(settings.readBoolEntry("/SkipTaskbar"));
- mWithdrawn = settings.readBoolEntry("/Withdraw");
+ setBalloonTimeout(config->readNumEntry("BalloonTimeout", 4000));
+ mCustomIcon = config->readEntry("CustomIcon", TQString::null);
+ setDockWhenMinimized(config->readBoolEntry("DockWhenMinimized", false));
+ setSkipTaskbar(config->readBoolEntry("SkipTaskbar", false));
+ mWithdrawn = config->readBoolEntry("Withdraw", false);
dock();
-
- /*
- * Since we are getting restored, it is likely that the application that we
- * are interested in has already been started (if we didnt launch it).
- * So we scan the list of windows and grab the first one that satisfies us
- * This implicitly assumes that if mPid!=0 then we launched it. Wait till
- * the application really shows itself up before we do a scan (the reason
- * why we have 2s
- */
- if (!mPid) TQTimer::singleShot(2000, this, SLOT(scanClients()));
-
- return true;
+ scanClients(); // Grab window
+ if (mWithdrawn)
+ {
+ withdraw();
+ }
+ else
+ {
+ map();
+ }
+ return true;
}
// End kicking butt