summaryrefslogtreecommitdiffstats
path: root/src/tdedocker.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/tdedocker.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/tdedocker.cpp')
-rw-r--r--src/tdedocker.cpp139
1 files changed, 41 insertions, 98 deletions
diff --git a/src/tdedocker.cpp b/src/tdedocker.cpp
index 2b404c7..2b24cf5 100644
--- a/src/tdedocker.cpp
+++ b/src/tdedocker.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2004 Girish Ramakrishnan All Rights Reserved.
- *
+ *
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -19,7 +19,6 @@
// $Id: tdedocker.cpp,v 1.24 2005/02/04 10:25:46 cs19713 Exp $
-#include <tqsessionmanager.h>
#include <tqdir.h>
#include <tqfile.h>
#include <tqtextcodec.h>
@@ -27,6 +26,8 @@
#include <tqtimer.h>
#include <tqstring.h>
+#include <tdecmdlineargs.h>
+#include <tdeconfig.h>
#include <tdelocale.h>
#include "trace.h"
@@ -39,83 +40,37 @@
#include <stdio.h>
#include <stdlib.h>
-// #define TMPFILE_PREFIX TQString("/tmp/tdedocker.")
-#define TMPFILE_PREFIX TQDir::homeDirPath() + "/.tdedocker."
+#define TMPFILE_PREFIX TQString("/tmp/tdedocker.")
-TDEDocker::TDEDocker(int& argc, char** argv)
- :TQApplication(argc, argv), mTrayLabelMgr(0)
+TDEDocker::TDEDocker()
+ : TDEApplication(), mTrayLabelMgr(NULL), firstSaveState(true)
{
INIT_TRACE();
-
- // Attempt doing anything only if the CLI arguments were good
- opterr = 0; // suppress the warning
- int option;
- while ((option = getopt(argc, argv, TrayLabelMgr::options().latin1())) != EOF)
- {
- if (option == '?')
- {
- if (optopt == 'v') printVersion(); else printUsage(optopt);
- ::exit(0);
- }
- }
-
/*
* Detect and transfer control to previous instance (if one exists)
- * _KDOCKER_RUNNING is a X Selection. We start out by trying to locate the
+ * _TDEDOCKER_RUNNING is a X Selection. We start out by trying to locate the
* selection owner. If someone else owns it, transfer control to that
* instance of TDEDocker
*/
Display *display = TQPaintDevice::x11AppDisplay();
- Atom tdedocker = XInternAtom(display, "_KDOCKER_RUNNING", False);
+ Atom tdedocker = XInternAtom(display, "_TDEDOCKER_RUNNING", False);
Window prev_instance = XGetSelectionOwner(display, tdedocker);
if (prev_instance == None)
{
- mSelectionOwner = XCreateSimpleWindow(display, tqt_xrootwin(), 1, 1, 1,
- 1, 1, 1, 1);
+ if (TDEApplication::kApplication()->isRestored())
+ {
+ // Required so that the saved config is correctly loaded
+ // (see TrayLabelMgr::doRestoreSession() for usage)
+ TDEApplication::kApplication()->sessionConfig();
+ }
+ mSelectionOwner = XCreateSimpleWindow(display, tqt_xrootwin(), 1, 1, 1, 1, 1, 1, 1);
XSetSelectionOwner(display, tdedocker, mSelectionOwner, CurrentTime);
TRACE("Selection owner set to 0x%x", (unsigned) mSelectionOwner);
mTrayLabelMgr = TrayLabelMgr::instance();
}
else
- notifyPreviousInstance(prev_instance); // does not return
-}
-
-void TDEDocker::printVersion(void)
-{
- tqDebug("TQt: %s", tqVersion());
- tqDebug("TDEDocker: %s", KDOCKER_APP_VERSION);
-}
-
-// Prints the CLI arguments. Does not return
-void TDEDocker::printUsage(char optopt)
-{
- if (optopt != 'h') tqDebug("%s", i18n("tdedocker: invalid option -- %1").arg(optopt).local8Bit().data());
-
- tqDebug("%s", i18n("Usage: TDEDocker [options] command\n").local8Bit().data());
- tqDebug("%s", i18n("Docks any application into the system tray\n").local8Bit().data());
- tqDebug("%s", i18n("command \tCommand to execute\n").local8Bit().data());
- tqDebug("%s", i18n("Options").local8Bit().data());
- tqDebug("%s", i18n("-a \tShow author information").local8Bit().data());
- tqDebug("%s", i18n("-b \tDont warn about non-normal windows (blind mode)").local8Bit().data());
- tqDebug("%s", i18n("-d \tDisable session management").local8Bit().data());
- tqDebug("%s", i18n("-e \tEnable session management").local8Bit().data());
- tqDebug("%s", i18n("-f \tDock window that has the focus(active window)").local8Bit().data());
- tqDebug("%s", i18n("-h \tDisplay this help").local8Bit().data());
- tqDebug("%s", i18n("-i icon\tCustom dock Icon").local8Bit().data());
- tqDebug("%s", i18n("-l \tLaunch on startup").local8Bit().data());
- tqDebug("%s", i18n("-m \tKeep application window mapped (dont hide on dock)").local8Bit().data());
- tqDebug("%s", i18n("-o \tDock when obscured").local8Bit().data());
- tqDebug("%s", i18n("-p secs\tSet ballooning timeout (popup time)").local8Bit().data());
- tqDebug("%s", i18n("-q \tDisable ballooning title changes (quiet)").local8Bit().data());
- tqDebug("%s", i18n("-t \tRemove this application from the task bar").local8Bit().data());
- tqDebug("%s", i18n("-v \tDisplay version").local8Bit().data());
- tqDebug("%s", i18n("-w wid \tWindow id of the application to dock\n").local8Bit().data());
-
- tqDebug("%s", i18n("NOTE: Use -d for all startup scripts.\n").local8Bit().data());
-
- tqDebug("%s", i18n("Bugs and wishes to [email protected]").local8Bit().data());
- tqDebug("%s", i18n("Project information at http://tdedocker.sourceforge.net").local8Bit().data());
+ notifyPreviousInstance(prev_instance); // does not return
}
void TDEDocker::notifyPreviousInstance(Window prevInstance)
@@ -128,18 +83,22 @@ void TDEDocker::notifyPreviousInstance(Window prevInstance)
TQFile f(TMPFILE_PREFIX + TQString().setNum(getpid()));
if (!f.open(IO_WriteOnly)) return;
TQTextStream s(&f);
-
- /*
- * Its normal to use TDEDocker in startup scripts. We could be getting restored
- * from a session at the same time. So, if we were getting restored and
- * another instance already exists, send across the session id. Remember, qt
- * strips out all the arguments that it understands. So need to do it by hand.
- */
- if (isSessionRestored())
- s << argv()[0] << " " << "-session" << " " << sessionId();
- else
- for (int i = 0; i < argc(); i++) s << argv()[i] << " ";
+ // Its normal to use TDEDocker in startup scripts. We could be getting restored
+ // from a session at the same time, so in such case pass along the info.
+ if (isRestored())
+ {
+ s << TDECmdLineArgs::appName() << " --restore-internal";
+ }
+ else
+ {
+ TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
+ s << TDECmdLineArgs::appName();
+ for (int i = 0; i < args->count(); i++)
+ {
+ s << " " << args->arg(i);
+ }
+ }
f.close();
/*
@@ -154,7 +113,7 @@ void TDEDocker::notifyPreviousInstance(Window prevInstance)
dock_event.type = ClientMessage;
dock_event.message_type = 0x220679; // it all started this day
dock_event.format = 8;
- dock_event.data.l[0] = 0xBABE; // love letter ;)
+ dock_event.data.l[0] = 0xBABE; // love letter ;)
dock_event.data.l[1] = getpid();
XSendEvent(display, prevInstance, False, 0, (XEvent *) &dock_event);
XSync(display, False);
@@ -179,7 +138,7 @@ bool TDEDocker::x11EventFilter(XEvent * event)
client->data.l[1], (unsigned) mSelectionOwner);
char tmp[50];
struct stat buf;
- sprintf(tmp, TQString(TMPFILE_PREFIX "%ld").local8Bit(), client->data.l[1]);
+ sprintf(tmp, TQString(TMPFILE_PREFIX+"%ld").local8Bit(), client->data.l[1]);
if (stat(tmp, &buf) || (getuid()!=buf.st_uid))
{
/*
@@ -204,30 +163,14 @@ bool TDEDocker::x11EventFilter(XEvent * event)
mTrayLabelMgr->processCommand(argv);
return TRUE;
}
- else return mTrayLabelMgr->x11EventFilter(event);
-}
-
-/*
- * XSMP Support
- */
-void TDEDocker::saveState(TQSessionManager &sm)
-{
- TQString sf = mTrayLabelMgr->saveSession();
-
- TQStringList discard_command;
- discard_command << "rm" << sf;
- sm.setDiscardCommand(discard_command);
-
- sm.setRestartHint(TQSessionManager::RestartIfRunning);
- TQStringList restart_command;
- restart_command << this->argv()[0]
- << "-session" << sm.sessionId();
- sm.setRestartCommand(restart_command);
-
- TRACE("SessionFile=%s AppName=%s", sf.latin1(), this->argv()[0]);
- DUMP_TRACE(TQDir::homeDirPath() + "/tdedocker.trace");
- // sm.setRestartCommand(applicationFilePath());
+ else
+ {
+ if (mTrayLabelMgr->x11EventFilter(event))
+ {
+ return true;
+ }
+ return TDEApplication::x11EventFilter(event);
+ }
}
-
#include "tdedocker.moc"