From cc5c30c9cbdce2693d284c57ae4671017bf0660c Mon Sep 17 00:00:00 2001 From: Paul Tagliamonte Date: Fri, 15 Apr 2011 14:48:05 -0400 Subject: Integrating fbautostart into the Fluxbox tree. This change merges fbautostart into fluxbox. fbautostart has been re-licensed under MIT to allow for this. I've added the util/fbautostart directory, and tweeked the build chain to include fbautostart. I've also added in a few docs. Those are the only changes outside the util/fbautostart folder. It's been noted in the ChangeLog, but fbautostart changes (since it might be a bit more "high-volume") should be maintained in util/fbautostart/ChangeLog. The XDG spec can be found at: - http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html --- ChangeLog | 5 + configure.in | 18 +- doc/Makefile.am | 17 +- doc/asciidoc/fbautostart.txt | 85 ++++++++ doc/fbautostart.1 | 110 ++++++++++ doc/fbautostart.1.in | 110 ++++++++++ util/Makefile.am | 7 +- util/fbautostart/AUTHORS | 2 + util/fbautostart/COPYRIGHT | 21 ++ util/fbautostart/ChangeLog | 42 ++++ util/fbautostart/Makefile.am | 4 + util/fbautostart/THANKS | 10 + util/fbautostart/include/dot_desktop.hh | 55 +++++ util/fbautostart/include/fbautostart.hh | 147 +++++++++++++ util/fbautostart/src/dot_desktop.cc | 147 +++++++++++++ util/fbautostart/src/fbautostart.cc | 356 ++++++++++++++++++++++++++++++++ util/fbautostart/src/main.cc | 90 ++++++++ 17 files changed, 1215 insertions(+), 11 deletions(-) create mode 100644 doc/asciidoc/fbautostart.txt create mode 100644 doc/fbautostart.1 create mode 100644 doc/fbautostart.1.in create mode 100644 util/fbautostart/AUTHORS create mode 100644 util/fbautostart/COPYRIGHT create mode 100644 util/fbautostart/ChangeLog create mode 100644 util/fbautostart/Makefile.am create mode 100644 util/fbautostart/THANKS create mode 100644 util/fbautostart/include/dot_desktop.hh create mode 100644 util/fbautostart/include/fbautostart.hh create mode 100644 util/fbautostart/src/dot_desktop.cc create mode 100644 util/fbautostart/src/fbautostart.cc create mode 100644 util/fbautostart/src/main.cc diff --git a/ChangeLog b/ChangeLog index 8965c26..87f8709 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,11 @@ Changes for 1.3.1 +*11/04/07: + * Importing the fbautostart codebase into the tree. This creates a new binary + called fbautostart(1). Documentation added to the global docs. (Paul) + util/fbautostart/* + *11/02/25: * Bugfix: submenus didn't hide if session*menuDelay was > 0 (Mathias) FbTk/Menu.cc AttentionHandler.cc diff --git a/configure.in b/configure.in index 1d69f34..d62b04b 100644 --- a/configure.in +++ b/configure.in @@ -639,9 +639,14 @@ else CONFIGOPTS="$CONFIGOPTS --disable-fribidi" fi - - - +AC_MSG_CHECKING([whether to build support for xdg autostarting]) +FBAUTOSTART=0 +AC_ARG_ENABLE(fbautostart, + [ --enable-fbautostart build fbautostart (xdg autostart utility) ([default=no])], + AC_DEFINE(USE_FBAUTOSTART, 1, " build the fbautostart xdg autostart utility") + FBAUTOSTART=1 +) +AM_CONDITIONAL(USE_FBAUTOSTART, test x$FBAUTOSTART = x1) AC_ARG_WITH( menu, @@ -730,6 +735,7 @@ src/FbTk/Makefile src/tests/Makefile util/Makefile util/fbrun/Makefile +util/fbautostart/Makefile data/Makefile data/styles/Makefile data/styles/BlueFlux/Makefile @@ -804,5 +810,11 @@ AC_MSG_RESULT([Using '$CXX' for C++ compiler.]) AC_MSG_RESULT([Building with '$CXXFLAGS' for C++ compiler flags.]) AC_MSG_RESULT([Building with '$LIBS' for linker flags.]) AC_MSG_RESULT([]) +AC_MSG_RESULT([Beta Features being Built:]) +AC_MSG_RESULT([(Enable beta features with --enable-FEATURE_NAME)]) +AC_MSG_RESULT([]) +AC_MSG_RESULT([fbautostart: $FBAUTOSTART]) +AC_MSG_RESULT([]) +AC_MSG_RESULT([]) AC_MSG_RESULT([Now build $PACKAGE with 'make']) AC_MSG_RESULT([]) diff --git a/doc/Makefile.am b/doc/Makefile.am index 008e318..07c1f93 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -1,15 +1,18 @@ # doc/Makefile.am for Fluxbox 0.9 - an X11 Window manager # Makefile.am for fluxbox/doc -CLEANFILES = fluxbox.1 fbrun.1 fbsetbg.1 fbsetroot.1 startfluxbox.1 fluxbox-apps.5 \ - fluxbox-keys.5 fluxbox-menu.5 fluxbox-remote.1 fluxbox-style.5 +CLEANFILES = fluxbox.1 fbrun.1 fbsetbg.1 fbsetroot.1 startfluxbox.1 fluxbox-remote.1 \ + fbautostart.1 fluxbox-apps.5 fluxbox-keys.5 fluxbox-menu.5 fluxbox-style.5 + MAINTAINERCLEANFILES = Makefile.in -man_MANS = fluxbox.1 fbrun.1 fbsetbg.1 fbsetroot.1 fluxbox-apps.5 \ - fluxbox-keys.5 fluxbox-menu.5 fluxbox-remote.1 fluxbox-style.5 \ - startfluxbox.1 + +man_MANS = fluxbox.1 fbrun.1 fbsetbg.1 fbsetroot.1 startfluxbox.1 fluxbox-remote.1 \ + fbautostart.1 fluxbox-apps.5 fluxbox-keys.5 fluxbox-menu.5 fluxbox-style.5 + EXTRA_DIST=startfluxbox.1.in CODESTYLE \ - fluxbox.1.in fbrun.1.in fbsetbg.1.in fbsetroot.1.in fluxbox-apps.5.in \ - fluxbox-keys.5.in fluxbox-menu.5.in fluxbox-remote.1.in fluxbox-style.5.in + fluxbox.1.in fbrun.1.in fbsetbg.1.in fbsetroot.1.in fluxbox-remote.1.in fbautostart.1.in \ + fluxbox-keys.5.in fluxbox-menu.5.in fluxbox-apps.5.in fluxbox-style.5.in + distclean-local: rm -f *\~ diff --git a/doc/asciidoc/fbautostart.txt b/doc/asciidoc/fbautostart.txt new file mode 100644 index 0000000..0ad7e05 --- /dev/null +++ b/doc/asciidoc/fbautostart.txt @@ -0,0 +1,85 @@ +fbautostart(1) +============== +Paul Tagliamonte +v2.7.0, 14 October 2010 +:man source: fbautostart.txt +:man version: {revision} +:man manual: fbautostart Manual + +NAME +---- +fbautostart - Autostart all XDG applications + +SYNOPSIS +-------- +*fbautostart* ['options'] + +DESCRIPTION +----------- +*fbautostart(1)* is an XDG complaint startup tool. This will +go through the directories set up by the spec, and start all +applications that match it's current identifier. You may change +that identifier with the *--window-manager* flag. + +This tool has almost no library dependencies and was written to be smart +about that sort of stuff. There is a greater then average chance +that you will find a bug, since it is a from-scratch implementation of the +.desktop spec. Pleas report bugs. Please. + +FILES +----- +*~/.config/autostart*:: + This folder contains the default user XDG dot-desktop files that + will be run ( unless it's overridden by an ENV variable ) + +*/etc/xdg*:: + This folder contains the default system XDG dot-desktop files that + will be run ( unless it's overridden by an ENV variable ) + + +OPTIONS +------- +*--noexec*:: + Do not execute any of the files, + rather, display what would have been run + +*--window-manager* ['WMNAME']:: + Override the compile-time default window + manager, and work on behalf of this instead. + This is helpful if you'd like to use this tool in + place of another DE's normal XDG Autostarting + application + +*--license*:: + Show license information + +*--version*:: + Show basic version information + +*--help*:: + Show basic usage and flags + +ENVIRONMENT VARIABLES +--------------------- +*XDG_CONFIG_HOME*:: + The XDG root directory for the user's startup + files, which may override the global startup files. + +*XDG_CONFIG_DIRS*:: + The root XDG directory, where global XDG files are + maintained. + + +EXAMPLE +------- +.... +fbautostart +.... + +AUTHORS +------- +Paul Tagliamonte for fbautostart 2.7 + +SEE ALSO +-------- +fluxbox(1) diff --git a/doc/fbautostart.1 b/doc/fbautostart.1 new file mode 100644 index 0000000..0d5d41d --- /dev/null +++ b/doc/fbautostart.1 @@ -0,0 +1,110 @@ +'\" t +.\" Title: fbautostart +.\" Author: [see the "AUTHORS" section] +.\" Generator: DocBook XSL Stylesheets v1.75.2 +.\" Date: 01/31/2011 +.\" Manual: fbautostart Manual +.\" Source: fbautostart.txt +.\" Language: English +.\" +.TH "FBAUTOSTART" "1" "01/31/2011" "fbautostart\&.txt" "fbautostart Manual" +.\" ----------------------------------------------------------------- +.\" * Define some portability stuff +.\" ----------------------------------------------------------------- +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.\" http://bugs.debian.org/507673 +.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.\" ----------------------------------------------------------------- +.\" * set default formatting +.\" ----------------------------------------------------------------- +.\" disable hyphenation +.nh +.\" disable justification (adjust text to left margin only) +.ad l +.\" ----------------------------------------------------------------- +.\" * MAIN CONTENT STARTS HERE * +.\" ----------------------------------------------------------------- +.SH "NAME" +fbautostart \- Autostart all XDG applications +.SH "SYNOPSIS" +.sp +\fBfbautostart\fR [\fIoptions\fR] +.SH "DESCRIPTION" +.sp +\fBfbautostart(1)\fR is an XDG complaint startup tool\&. This will go through the directories set up by the spec, and start all applications that match it\(cqs current identifier\&. You may change that identifier with the \fB\-\-window\-manager\fR flag\&. +.sp +This tool has almost no library dependencies and was written to be smart about that sort of stuff\&. There is a greater then average chance that you will find a bug, since it is a from\-scratch implementation of the \&.desktop spec\&. Pleas report bugs\&. Please\&. +.SH "FILES" +.PP +\fB~/\&.config/autostart\fR +.RS 4 +This folder contains the default user XDG dot\-desktop files that will be run ( unless it\(cqs overridden by an ENV variable ) +.RE +.PP +\fB/etc/xdg\fR +.RS 4 +This folder contains the default system XDG dot\-desktop files that will be run ( unless it\(cqs overridden by an ENV variable ) +.RE +.SH "OPTIONS" +.PP +\fB\-\-noexec\fR +.RS 4 +Do not execute any of the files, rather, display what would have been run +.RE +.PP +\fB\-\-window\-manager\fR [\fIWMNAME\fR] +.RS 4 +Override the compile\-time default window manager, and work on behalf of this instead\&. This is helpful if you\(cqd like to use this tool in place of another DE\(cqs normal XDG Autostarting application +.RE +.PP +\fB\-\-license\fR +.RS 4 +Show license information +.RE +.PP +\fB\-\-version\fR +.RS 4 +Show basic version information +.RE +.PP +\fB\-\-help\fR +.RS 4 +Show basic usage and flags +.RE +.SH "ENVIRONMENT VARIABLES" +.PP +\fBXDG_CONFIG_HOME\fR +.RS 4 +The XDG root directory for the user\(cqs startup files, which may override the global startup files\&. +.RE +.PP +\fBXDG_CONFIG_DIRS\fR +.RS 4 +The root XDG directory, where global XDG files are maintained\&. +.RE +.SH "EXAMPLE" +.sp +.if n \{\ +.RS 4 +.\} +.nf +fbautostart +.fi +.if n \{\ +.RE +.\} +.SH "AUTHORS" +.sp +Paul Tagliamonte <\m[blue]\fBpaultag@ubuntu\&.com\fR\m[]\&\s-2\u[1]\d\s+2> for fbautostart 2\&.7 +.SH "SEE ALSO" +.sp +fluxbox(1) +.SH "NOTES" +.IP " 1." 4 +paultag@ubuntu.com +.RS 4 +\%mailto:paultag@ubuntu.com +.RE diff --git a/doc/fbautostart.1.in b/doc/fbautostart.1.in new file mode 100644 index 0000000..0d5d41d --- /dev/null +++ b/doc/fbautostart.1.in @@ -0,0 +1,110 @@ +'\" t +.\" Title: fbautostart +.\" Author: [see the "AUTHORS" section] +.\" Generator: DocBook XSL Stylesheets v1.75.2 +.\" Date: 01/31/2011 +.\" Manual: fbautostart Manual +.\" Source: fbautostart.txt +.\" Language: English +.\" +.TH "FBAUTOSTART" "1" "01/31/2011" "fbautostart\&.txt" "fbautostart Manual" +.\" ----------------------------------------------------------------- +.\" * Define some portability stuff +.\" ----------------------------------------------------------------- +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.\" http://bugs.debian.org/507673 +.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.\" ----------------------------------------------------------------- +.\" * set default formatting +.\" ----------------------------------------------------------------- +.\" disable hyphenation +.nh +.\" disable justification (adjust text to left margin only) +.ad l +.\" ----------------------------------------------------------------- +.\" * MAIN CONTENT STARTS HERE * +.\" ----------------------------------------------------------------- +.SH "NAME" +fbautostart \- Autostart all XDG applications +.SH "SYNOPSIS" +.sp +\fBfbautostart\fR [\fIoptions\fR] +.SH "DESCRIPTION" +.sp +\fBfbautostart(1)\fR is an XDG complaint startup tool\&. This will go through the directories set up by the spec, and start all applications that match it\(cqs current identifier\&. You may change that identifier with the \fB\-\-window\-manager\fR flag\&. +.sp +This tool has almost no library dependencies and was written to be smart about that sort of stuff\&. There is a greater then average chance that you will find a bug, since it is a from\-scratch implementation of the \&.desktop spec\&. Pleas report bugs\&. Please\&. +.SH "FILES" +.PP +\fB~/\&.config/autostart\fR +.RS 4 +This folder contains the default user XDG dot\-desktop files that will be run ( unless it\(cqs overridden by an ENV variable ) +.RE +.PP +\fB/etc/xdg\fR +.RS 4 +This folder contains the default system XDG dot\-desktop files that will be run ( unless it\(cqs overridden by an ENV variable ) +.RE +.SH "OPTIONS" +.PP +\fB\-\-noexec\fR +.RS 4 +Do not execute any of the files, rather, display what would have been run +.RE +.PP +\fB\-\-window\-manager\fR [\fIWMNAME\fR] +.RS 4 +Override the compile\-time default window manager, and work on behalf of this instead\&. This is helpful if you\(cqd like to use this tool in place of another DE\(cqs normal XDG Autostarting application +.RE +.PP +\fB\-\-license\fR +.RS 4 +Show license information +.RE +.PP +\fB\-\-version\fR +.RS 4 +Show basic version information +.RE +.PP +\fB\-\-help\fR +.RS 4 +Show basic usage and flags +.RE +.SH "ENVIRONMENT VARIABLES" +.PP +\fBXDG_CONFIG_HOME\fR +.RS 4 +The XDG root directory for the user\(cqs startup files, which may override the global startup files\&. +.RE +.PP +\fBXDG_CONFIG_DIRS\fR +.RS 4 +The root XDG directory, where global XDG files are maintained\&. +.RE +.SH "EXAMPLE" +.sp +.if n \{\ +.RS 4 +.\} +.nf +fbautostart +.fi +.if n \{\ +.RE +.\} +.SH "AUTHORS" +.sp +Paul Tagliamonte <\m[blue]\fBpaultag@ubuntu\&.com\fR\m[]\&\s-2\u[1]\d\s+2> for fbautostart 2\&.7 +.SH "SEE ALSO" +.sp +fluxbox(1) +.SH "NOTES" +.IP " 1." 4 +paultag@ubuntu.com +.RS 4 +\%mailto:paultag@ubuntu.com +.RE diff --git a/util/Makefile.am b/util/Makefile.am index d0895ae..7cf9392 100644 --- a/util/Makefile.am +++ b/util/Makefile.am @@ -1,5 +1,10 @@ # util/Makefile.am for Fluxbox -SUBDIRS= fbrun + +if USE_FBAUTOSTART + UTIL_FBAUTOSTART = fbautostart +endif + +SUBDIRS= fbrun $(UTIL_FBAUTOSTART) INCLUDES= -I$(top_srcdir)/src -I$(top_srcdir)/src/FbTk bin_SCRIPTS= fbsetbg fluxbox-generate_menu startfluxbox bin_PROGRAMS= fbsetroot fluxbox-update_configs fluxbox-remote diff --git a/util/fbautostart/AUTHORS b/util/fbautostart/AUTHORS new file mode 100644 index 0000000..c4bbf63 --- /dev/null +++ b/util/fbautostart/AUTHORS @@ -0,0 +1,2 @@ +* Paul Tagliamonte + diff --git a/util/fbautostart/COPYRIGHT b/util/fbautostart/COPYRIGHT new file mode 100644 index 0000000..7ef85a0 --- /dev/null +++ b/util/fbautostart/COPYRIGHT @@ -0,0 +1,21 @@ +Copyright (c) 2011 The Fluxbox Team +Copyright (c) 2010 Paul Tagliamonte + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + diff --git a/util/fbautostart/ChangeLog b/util/fbautostart/ChangeLog new file mode 100644 index 0000000..7572194 --- /dev/null +++ b/util/fbautostart/ChangeLog @@ -0,0 +1,42 @@ +2011-04-09 Paul Tagliamonte + +* Fixed the license issue in the version and lecture +printouts. Still said GPL. Pfft! +* Moved the main method from fbautostart.cc to main.cc. +* Put fbautostart functions into the fbautostart namespace, +just in case we must use some of the XDG bindings from outside +of fbautostart it's self. + +2011-04-07 Paul Tagliamonte + +* Renamed the .cpp files to .cc, and .h files to .hh. +all source files affected. +* Licese change! Beware! License Change! We're now MIT +licensed. + +2010-11-28 Paul Tagliamonte + +* Removed the #define for the window manager setting in +include/fbautostart.h. It's now a const char, and dynamic +with the new --window-manager flag. +* Changed fbautostart to error out when you pass in a bum +flag. This caused me great pain the other day. Fixed now. +* Forgot to bump the version number. It's now version 2.71828. +Both of these changes were in src/fbautostart.cpp + +2010-10-21 Paul Tagliamonte + +* Bugfixes for random crap for XDG env issues. +This is a fix for issues that I missed when fixing +Segaja's issues. + +2010-10-15 Paul Tagliamonte + +* Bugfixes for random crap. Rewrote stuff to make +more sense. +* Fixed a few XDG spec issues. Should be betters now. +* Fixed a bug with env vars. Thanks, Segaja. + +2010-10-14 Paul Tagliamonte + +* Adding in the basic code stuff. Initial Release. diff --git a/util/fbautostart/Makefile.am b/util/fbautostart/Makefile.am new file mode 100644 index 0000000..9e6639a --- /dev/null +++ b/util/fbautostart/Makefile.am @@ -0,0 +1,4 @@ +# FBAutoStart automakefile. +INCLUDES = -I./include +bin_PROGRAMS = fbautostart +fbautostart_SOURCES = src/main.cc src/fbautostart.cc src/dot_desktop.cc diff --git a/util/fbautostart/THANKS b/util/fbautostart/THANKS new file mode 100644 index 0000000..056d312 --- /dev/null +++ b/util/fbautostart/THANKS @@ -0,0 +1,10 @@ +Thanks to Segaja on irc.freenode.net ( #fluxbox ) for + finding the first bug with the XDG Env vars. Thanks + So much! + +Thanks to ak|ra for reviewing my code and providing some + truely outstanding feedback You rock! + +Thanks to Michael Gilbert for a package review, and some + suggestions on how to better format the source tree. + Thanks a ton, man, you're a rockstar! diff --git a/util/fbautostart/include/dot_desktop.hh b/util/fbautostart/include/dot_desktop.hh new file mode 100644 index 0000000..c234061 --- /dev/null +++ b/util/fbautostart/include/dot_desktop.hh @@ -0,0 +1,55 @@ +/* + * dot_desktop.hh + * + * This file is part of the Fluxbox Autostart ( fbautostart ) + * Utility. + * + * Copyright (C) 2011 by Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#ifndef _DOT_DESKTOP_H +#define _DOT_DESKTOP_H ohai + +#include + +namespace fbautostart { + class dot_desktop_attr { + public: + std::string attr; + std::string value; + }; + + class dot_desktop { + protected: + std::vector * attr; + std::string file; + std::string id; + public: + dot_desktop( std::string s, std::string id ); + void load(); + std::string getAttr( std::string sx ); + bool validate(); + std::string getFile(); + std::string getID(); + }; +} +#endif diff --git a/util/fbautostart/include/fbautostart.hh b/util/fbautostart/include/fbautostart.hh new file mode 100644 index 0000000..6ce1144 --- /dev/null +++ b/util/fbautostart/include/fbautostart.hh @@ -0,0 +1,147 @@ +/* + * fbautostart.hh + * + * This file is part of the Fluxbox Autostart ( fbautostart ) + * Utility. + * + * Copyright (C) 2011 by Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#ifndef _FBAUTOSTART_H +#define _FBAUTOSTART_H ohai + +#define PACKAGE "fbautostart" +#define PACKAGE_VERSION "2.71828" + +#ifndef _DEBUG_MODE +#define _DEBUG_MODE 0 +#endif + +extern const char * _ON_BEHALF_OF; +extern bool noexec; + +#include "dot_desktop.hh" + +#define _DEFAULT_XDG_HOME "~/.config" +#define _DEFAULT_XDG_DIRS "/etc/xdg" +#define _XDG_AUTOSTART_DIR "/autostart/" + +// XXX: Please document these functions better. +// the @param names need to be fixed up as well. +// stuff like `foo' or `loc' sucks ass. +// -PRT + +namespace fbautostart { + + /** + * Print a help message to the user + */ + void help(); + + /** + * Lecture the user on correct invocation. + */ + void lecture(); + + /** + * Print version of fbautostart to stdout. + */ + void version(); + + /** + * Log an error to stderr. + * @param s std::string with the error message + */ + void logError( std::string s ); + + /** + * Log an error to stderr, to print a single integer. + * @param i int to print to stderr + */ + void logError( int i ); + + /** + * Print the string to the screen if debug mode is enabled. + * @param s std::string with the message to print to the screen + */ + void debug( const std::string & s ); + + /** + * Print a std::vector to the screen if debug mode is enabled. + * @param foo std::vector to dump + */ + void debug( const std::vector & foo ); + + /** + * Print a size_t to the screen if debug mode is enabled. + * @param foo size_t to be printed to the screen + */ + void debug( size_t foo ); + + /** + * processArgs should only be called by main, and pass the main arguments to processArgs. + * @param argc number of arguments in args + * @param argv char array of arguments + */ + void processArgs( int argc, char ** args ); + + /** + * Run a command on the system + * @param appl command to run + * @return return status of the application + */ + int runCommand( std::string appl ); + + /** + * Break a line up based on a ":" + * @param locs the std::vector to push tokens back into + * @param lines to process + */ + void breakupLine( std::vector * locs, std::string lines ); + + /** + * Fix paths with a tilde in them. + * @param locs a std::vector of paths to fix up + * @param home the home path of the user, absolute + */ + void fixHomePathing( std::vector * locs, std::string home ); + + /** + * Get configuration directories according to the XDG spec. + * @param loc std::vector to load up results in + * @return returns false if we are unable to complete processing (such as null $HOME) + */ + bool getConfDirs( std::vector & loc ); + + /** + * Get all the .desktop files to process. + * @param dirs the directories to search + * @param out_files the vector we are loading up + * @return if we were able to complete processing with success + */ + bool getDesktopFiles( + const std::vector & dirs, + std::vector & out_files + ); +} + +#endif diff --git a/util/fbautostart/src/dot_desktop.cc b/util/fbautostart/src/dot_desktop.cc new file mode 100644 index 0000000..4c7ca68 --- /dev/null +++ b/util/fbautostart/src/dot_desktop.cc @@ -0,0 +1,147 @@ +/* + * dot_desktop.cc + * + * This file is part of the Fluxbox Autostart ( fbautostart ) + * Utility. + * + * Copyright (C) 2011 by Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +/* + * BIG BOLDFACE WARNING: + * BIG BOLDFACE WARNING: + * BIG BOLDFACE WARNING: + * + * This is *NOT* a full implementation of the + * .desktop spec. If you decide to use this code + * for anything outside of basic basic use ( read: + * what we're using it for ) + * + * In fact, this is almost as bare bones as I can make it + * It will break on more then one directive, and barf to stderr + * when it finds something it thinks is disgusting. + * + * It also does not trim strings, so there may be whitespace crap + * screwing stuff up. + * + * This needs some love. Patches welcome. Don't suggest + * the GNOME library. That relies on GTK+. WTF, really GNOME. + * -- PRT + * + */ + +#define _DOT_DESKTOP_GIVEAWAY "[Desktop Entry]" + +#include +#include +#include + +#include "fbautostart.hh" + +fbautostart::dot_desktop::dot_desktop( std::string s, std::string id ) { + this->attr = new std::vector(); + this->file = s; + this->id = id; + this->load(); +} + +bool fbautostart::dot_desktop::validate() { + std::ifstream fp_in(this->file.c_str()); + std::string line; + bool ret = false; + bool gah = true; + while ( gah && std::getline(fp_in, line) ) { // XXX: This sucks. Fix me. + if ( line.substr(0,strlen(_DOT_DESKTOP_GIVEAWAY)) == _DOT_DESKTOP_GIVEAWAY ) { + // debug(""); + // debug("Found us a Desktop file!"); + ret = true; + gah = false; + } else if ( line.substr(0,1) == "#" || line.substr(0,1) == "" ) { // XXX: This sucks. Fix me. + // ok. comment or whitespace + } else { + ret = false; + gah = false; + + debug(""); + debug("Looks like the following file is not a desktop file."); + debug(this->file); + debug("The giveaway was:"); + debug(line); + } + } + fp_in.close(); + return ret; +} + +void fbautostart::dot_desktop::load() { + if ( this->validate() ) { + std::ifstream fp_in(this->file.c_str()); + std::string line; + + while ( std::getline(fp_in, line) ) { + int index = -1; + if ( line.substr(0,1) != "#" ) { + index = line.find("="); + if ( index > 0 ) { + std::string id = line.substr(0,index); + std::string data = line.substr(index+1,strlen(line.c_str())); + dot_desktop_attr * new_attr = new dot_desktop_attr; + new_attr->attr = id; + new_attr->value = data; + this->attr->push_back( new_attr ); + } else if ( line.substr(0,1) == "[" && line.substr(line.length()-1,line.length()) == "]" ) { + // debug("Found a new header:"); // XXX: This sucks. Fix me. + // debug(line); + } else if ( line == "" ) { + // just a blank line. + } else { + logError(""); + logError( "We've got an issue with the following file:" ); + logError( this->file ); + logError( "Line in question is: " ); + logError( line ); + } + } + } + fp_in.close(); + } else { + logError(""); + logError( "We've got an issue with the following file:" ); + logError( this->file ); + } +} + +std::string fbautostart::dot_desktop::getFile() { + return this->file; +} + +std::string fbautostart::dot_desktop::getID() { + return this->id; +} + +std::string fbautostart::dot_desktop::getAttr( std::string s ){ + for ( unsigned int i = 0; i < this->attr->size(); ++i ) { + if ( this->attr->at(i)->attr == s ) + return this->attr->at(i)->value; + } + return ""; +} diff --git a/util/fbautostart/src/fbautostart.cc b/util/fbautostart/src/fbautostart.cc new file mode 100644 index 0000000..dd3b81b --- /dev/null +++ b/util/fbautostart/src/fbautostart.cc @@ -0,0 +1,356 @@ +/* + * fbautostart.cc + * + * This file is part of the Fluxbox Autostart ( fbautostart ) + * Utility. + * + * Copyright (C) 2011 by Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "fbautostart.hh" + +#ifndef _FBAUTOSTART_CPP +#define _FBAUTOSTART_CPP foomanchu + +#define _APPNAME_ PACKAGE +#define _VERSION_ PACKAGE_VERSION + +#ifndef _ON_BEHALF_OF_DEFAULT + +/** + * I'm a bit biased on what this should + * be starting up for. Considering the + * name of this app and such. + */ + +#define _ON_BEHALF_OF_DEFAULT "FLUXBOX" +#endif + +const char * _ON_BEHALF_OF = _ON_BEHALF_OF_DEFAULT; + +bool noexec = false; + +void fbautostart::version() { + std::cout << "" << _APPNAME_ << " " << _VERSION_ << std::endl; +} + +void fbautostart::lecture() { + version(); + std::cout << "Copyright (C) 2011 The Fluxbox Team" << std::endl; + std::cout << "Copyright (C) 2010 Paul Tagliamonte" << std::endl; + std::cout << "This software is licensed under the MIT License." << std::endl; + std::cout << "This is free software: you are free to change and redistribute it." << std::endl; + std::cout << "There is NO WARRANTY, to the extent permitted by law." << std::endl; +} + +void fbautostart::help() { + std::cout << "Usage: fbautostart [OPTION] ... " << std::endl; + std::cout << "Startup all applications according to the" << std::endl; + std::cout << "XDG Spec. Right now, I'm hardcoded to think that" << std::endl; + std::cout << "I am doing this on behalf of '" << _ON_BEHALF_OF << "'" << std::endl; + + std::cout << std::endl; + + std::cout << "--license Print out license information" << std::endl; + std::cout << "--help Print out this message" << std::endl; + std::cout << "--noexec Don't exec, just do a dry run" << std::endl; + std::cout << "--window-manager ID Override hardcoded value ( " << _ON_BEHALF_OF << " )" << std::endl; + + std::cout << "" << std::endl; + + std::cout << "Copyleft (c) The Fluxbox Team, 2011, MIT License" << std::endl; + std::cout << "Copyleft (c) Paul Tagliamonte, 2010, MIT License" << std::endl; + // ^^^^^^^^^^^^^^^^ That is pretty fucking awesome + // Future maintainer: Your name must + // be exactly 16 chars long. kthx. + + std::cout << "" << std::endl; +} + +int fbautostart::runCommand( std::string appl ) { + /* + * The following is almost directly ripped off from + * Fluxbox's implementation. ( at ak|ra's behest ) + */ + + pid_t pid = fork(); + if (pid) + return pid; + + // get shell path from the environment + // + // this process exits immediately, so we don't have to + // worry about memleaks + std::string shell = getenv("SHELL"); + + if ( shell != "" ) + shell = "/bin/sh"; + + if ( ! noexec ) { // we'll do it live + execl( + shell.c_str(), + shell.c_str(), + "-c", + appl.c_str(), + static_cast(NULL) + ); + exit ( EXIT_SUCCESS ); + return pid; // compiler happy -> we are happy ;) + } else { // dummy mode ( test ) + std::cout << "Would have run: " << appl << std::endl; + exit(0); + return 0; + } +} + +void fbautostart::processArgs( int argc, char ** args ) { + for ( int i = 1; i < argc; ++i ) { + if ( strcmp(args[i], "--license") == 0 ) { + lecture(); + exit(0); + } else if ( strcmp(args[i], "--version") == 0 ) { + version(); + exit(0); + } else if ( strcmp(args[i], "--help") == 0 ) { + help(); + exit(0); + } else if ( strcmp(args[i], "--noexec") == 0 ) { + noexec = true; + } else if ( strcmp(args[i], "--window-manager") == 0 ) { + _ON_BEHALF_OF = args[i+1]; + i = i+1; + } else { + help(); + + std::cout << "Holy god. I have no idea what:" << std::endl; + std::cout << " " << args[i] << std::endl; + std::cout << "means. Try again :/" << std::endl; + std::cout << std::endl; + + exit(1); + } + } +} + +/* + * OK. Here's some Spec text. I accessed this data on + * October 14th, 2010. + * + * The URL was: + * http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html + * + * + * == Autostart Directories == + * + * The Autostart Directories are $XDG_CONFIG_DIRS/autostart as + * defined in accordance with the "Referencing this specification" + * section in the "desktop base directory specification". + * + * If the same filename is located under multiple Autostart Directories + * only the file under the most important directory should be used. + * + * Example: If $XDG_CONFIG_HOME is not set the Autostart Directory + * in the user's home directory is ~/.config/autostart/ + * + * Example: If $XDG_CONFIG_DIRS is not set the system wide Autostart + * Directory is /etc/xdg/autostart/ + * + * Example: If $XDG_CONFIG_HOME and $XDG_CONFIG_DIRS are not set and + * the two files /etc/xdg/autostart/foo.desktop and + * ~/.config/autostart/foo.desktop exist then only the file + * ~/.config/autostart/foo.desktop will be used because + * ~/.config/autostart/ is more important than /etc/xdg/autostart/ + */ + + +void fbautostart::logError( std::string s ) { // [e]: my error line + std::cerr << "[e]: " << s << std::endl; +} + +void fbautostart::logError( int i ) { // [e]: (int) n + std::cerr << "[e]: (int) " << i << std::endl; +} + +void fbautostart::debug( const std::string & s ) { // [l]: my debug line + if ( _DEBUG_MODE ) { + std::cout << "[l]: " << s << std::endl; + } +} + +void fbautostart::debug( const std::vector & foo ) { // [l]: my debug line + if ( _DEBUG_MODE ) { + std::cout << "[l]: The following is an array" << std::endl; + for ( unsigned int i = 0; i < foo.size(); ++i ) { + std::cout << "[l]: " << foo.at(i) << std::endl; + } + } +} + +void fbautostart::debug( size_t foo ) { // [l]: my debug line + if ( _DEBUG_MODE ) { + std::cout << "[l]: " << foo << std::endl; + } +} + +void fbautostart::breakupLine( std::vector * locs, std::string lines ) { + std::string token; + std::istringstream iss(lines); + while ( getline(iss, token, ':') ) { + token.append( _XDG_AUTOSTART_DIR ); // use the xdg autostart dir. + locs->push_back( token ); + } +} + +void fbautostart::fixHomePathing( std::vector * locs, std::string home ) { + for ( unsigned int i = 0; i < locs->size(); ++i ) { + if ( locs->at(i)[0] == '~' && locs->at(i)[1] == '/' ) { + debug(""); + debug("Fixing a path old / new path follows."); + debug(locs->at(i)); + locs->at(i).replace(0, 1, home ); + debug(locs->at(i)); + } + } +} + +bool fbautostart::getConfDirs( std::vector & loc ) { + + const char * xdg_home = getenv("XDG_CONFIG_HOME"); // See the spec for why + const char * xdg_dirs = getenv("XDG_CONFIG_DIRS"); // I'm using what I'm using. + const char * uzr_home = getenv("HOME"); + + if ( uzr_home != NULL ) { + + std::string XDG_home, XDG_dirs; + + if ( xdg_dirs != NULL ) { + debug( "We have an overridden xdg dir. Using it." ); + XDG_dirs = xdg_dirs; + } else { + XDG_dirs = _DEFAULT_XDG_DIRS; + } + + if ( xdg_home != NULL ) { + debug( "We have an overridden xdg home. Using it." ); + XDG_home = xdg_home; + } else { + XDG_home = _DEFAULT_XDG_HOME; + } + + debug("Following is the targets"); + debug(XDG_home); + debug(XDG_dirs); + + breakupLine( &loc, XDG_dirs ); + breakupLine( &loc, XDG_home ); + + for ( unsigned int i = 0; i < loc.size(); ++i ) + fixHomePathing( &loc, uzr_home ); + + debug(""); + debug("Using the following array to find files ( Expanded ): "); + debug(loc); + + return true; + } else { + logError( "the env var HOME is not set. Panic!" ); + return false; + } +} + +bool fbautostart::getDesktopFiles( + const std::vector & dirs, + std::vector & out_files +) { + std::vector files; + + for ( unsigned int i = 0; i < dirs.size(); ++i ) { + DIR * dp = NULL; + struct dirent * dirp = NULL; + if ( (dp = opendir(dirs.at(i).c_str())) == NULL ) { + if ( errno == ENOENT ) { // E(RROR) NO EXIST ( or whatever ) + debug(""); + debug("Looks like the dir does not exist. Dir follows."); + debug( dirs.at(i) ); + } else { + logError(""); + logError("Oh no! Error opening directory! Directory, then Errorno follows: "); + logError( dirs.at(i) ); + logError(errno); + return false; + } + } else { + while ((dirp = readdir(dp)) != NULL) { // for every file in the directory + std::string file(dirp->d_name); // char arrays suck + if ( file != "." && file != ".." ) { // make sure we don't use . / .. + int dupe = -1; // there's no -1st element, silly! + + for ( unsigned int n = 0; n < files.size(); ++n ) { + if ( files.at(n).getID() == file ) { // make sure it's unique + // ( as the xdg + // spec requires ) + + dupe = n; // there can be only one + // dupe in the array, so it's + // OK to think that there will + // be only one + } + } + + std::string desktop_filepath = dirs.at(i); + desktop_filepath.append(file); + dot_desktop new_file( desktop_filepath, file ); + + if ( dupe >= 0 ) { + files.at(dupe) = new_file; + } else { + files.push_back( new_file ); + } + } + } + closedir(dp); + } + } + + if ( ! files.empty() ) { + std::swap( files, out_files ); + return true; + } else { + return false; + } +} + +#endif diff --git a/util/fbautostart/src/main.cc b/util/fbautostart/src/main.cc new file mode 100644 index 0000000..09f2d10 --- /dev/null +++ b/util/fbautostart/src/main.cc @@ -0,0 +1,90 @@ +/* + * main.cc + * + * This file is part of the Fluxbox Autostart ( fbautostart ) + * Utility. + * + * Copyright (C) 2011 by Paul Tagliamonte + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#include + +#include "fbautostart.hh" + +using namespace std; + +int main ( int argc, char ** argv ) { + fbautostart::processArgs( argc, argv ); + + if ( noexec ) { + std::cout << "Warning: In noexec mode." << std::endl; + } + + std::cout << "Launching on behalf of " << _ON_BEHALF_OF << std::endl; + + std::vector files; + std::vector dirs; + + if ( fbautostart::getConfDirs( dirs ) ) { // if no directories barf in our face + if ( fbautostart::getDesktopFiles( dirs, files ) ) { // and we load everything with glee + for ( unsigned int i = 0; i < files.size(); ++i ) { // run through all the files + fbautostart::dot_desktop d = files.at(i); + bool happy = true; + std::string only = d.getAttr("OnlyShowIn"); // Only one per file ( per xdg ) + std::string noti = d.getAttr("NotShowIn"); // We'll ignore that until we care + // XXX: This is most likely a bug. + if ( only != "" ) { // even if an attr does not exist + // the object will return it as "". + int index = -1; + index = only.find(_ON_BEHALF_OF); // if we have our WM in the OnlyLaunch + if ( index < 0 ) { // we're disabled ( not found ) + happy = false; + fbautostart::debug(""); + fbautostart::debug("Not running the following app ( Excluded by a OnlyShowIn )"); + fbautostart::debug(d.getAttr("Name")); + } + } + if ( noti != "" ) { // (NotShowIn (don't show)) + int index = -1; + index = noti.find(_ON_BEHALF_OF); // if we have found our WM + if ( index >= 0 ) { // We're in Launch, stop from launching it. + happy = false; + fbautostart::debug(""); + fbautostart::debug("Forced into not running the following app ( Included by not being in NotShowIn )"); + fbautostart::debug(d.getAttr("Name")); + } + } + if ( d.getAttr("Hidden") == "" && happy ) { // If we sould exec + std::string appl = d.getAttr("Exec"); // get the line to run + if ( appl != "" ) { // if it's defined and ready to go + fbautostart::debug( "Processing File: "); + fbautostart::debug(d.getFile()); + fbautostart::runCommand( appl ); // kickoff (regardless of noexec) + } + } // otherwise, we're out of here. + } + return 0; + } + return 0xDEADBEEF; + } + return 0xCAFEBABE; +} -- cgit v0.11.2