diff options
Diffstat (limited to 'src/main.cc')
-rw-r--r-- | src/main.cc | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/main.cc b/src/main.cc new file mode 100644 index 0000000..b8190c5 --- /dev/null +++ b/src/main.cc | |||
@@ -0,0 +1,116 @@ | |||
1 | // main.cc for FbPager | ||
2 | // Copyright (c) 2003-2004 Henrik Kinnunen (fluxgen at users.sourceforge.net) | ||
3 | // | ||
4 | // Permission is hereby granted, free of charge, to any person obtaining a | ||
5 | // copy of this software and associated documentation files (the "Software"), | ||
6 | // to deal in the Software without restriction, including without limitation | ||
7 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
8 | // and/or sell copies of the Software, and to permit persons to whom the | ||
9 | // Software is furnished to do so, subject to the following conditions: | ||
10 | // | ||
11 | // The above copyright notice and this permission notice shall be included in | ||
12 | // all copies or substantial portions of the Software. | ||
13 | // | ||
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
17 | // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
19 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
20 | // DEALINGS IN THE SOFTWARE. | ||
21 | |||
22 | // $Id$ | ||
23 | |||
24 | #include "FbPager.hh" | ||
25 | #include "FbTk/App.hh" | ||
26 | |||
27 | #include <cstdlib> | ||
28 | #include <iostream> | ||
29 | #include <string> | ||
30 | #include "version.h" | ||
31 | |||
32 | using namespace std; | ||
33 | |||
34 | void showVersion() { | ||
35 | cout<<"FbPager "<<__fbpager_version<<": (c) 2004-2007 Henrik Kinnunen (fluxgen<at>fluxbox org)"<<endl; | ||
36 | } | ||
37 | |||
38 | void showUsage(const char * const appname) { | ||
39 | showVersion(); | ||
40 | cout<<"Usage: "<<endl | ||
41 | <<appname<<" <argument>"<<endl | ||
42 | <<"Arguments: "<<endl | ||
43 | <<" -display <displayname>"<<endl | ||
44 | <<" -w withdrawn state (i.e in the Slit)"<<endl | ||
45 | <<" -rc <filename> resource file (default: ~/.fluxbox/fbpager)"<<endl | ||
46 | <<" -sr show resources"<<endl | ||
47 | <<" -s <screen number> (default: 0)"<<endl | ||
48 | <<" -v show version"<<endl | ||
49 | <<" -h show this help"<<endl | ||
50 | <<" -l <layer> layer, values: top or bottom" << endl; | ||
51 | } | ||
52 | |||
53 | int main(int argc, char **argv) { | ||
54 | int screen_num = 0; | ||
55 | std::string displayname; | ||
56 | bool withdraw = false; | ||
57 | std::string resourcefile("~/.fluxbox/fbpager"); | ||
58 | bool ewmh = true; | ||
59 | bool fbhints = true; | ||
60 | bool show_resources = false; | ||
61 | int layer = -1; | ||
62 | for (int arg = 1; arg < argc; ++arg) { | ||
63 | string sarg = argv[arg]; | ||
64 | // if argument starts with "--" remove the first '-' | ||
65 | if (sarg[0] == '-' && sarg[1] == '-') | ||
66 | sarg.erase(0, 1); | ||
67 | |||
68 | if (sarg == "-display" && arg < argc - 1) { | ||
69 | displayname = argv[++arg]; | ||
70 | } else if (sarg == "-w") | ||
71 | withdraw = true; | ||
72 | else if (sarg == "-rc" && arg < argc - 1) | ||
73 | resourcefile = argv[++arg]; | ||
74 | else if (sarg == "-v") { | ||
75 | showVersion(); | ||
76 | exit(EXIT_SUCCESS); | ||
77 | } else if (sarg == "-s" && arg < argc - 1) { | ||
78 | screen_num = atoi(argv[++arg]); | ||
79 | } else if (sarg == "-sr") { | ||
80 | show_resources = true; | ||
81 | } else if (sarg == "-l") { | ||
82 | ++arg; | ||
83 | if (strcmp(argv[arg], "top")== 0) { | ||
84 | layer = 2; | ||
85 | } else if (strcmp(argv[arg], "bottom") == 0) { | ||
86 | layer = 0; | ||
87 | } | ||
88 | } else { | ||
89 | showUsage(argv[0]); | ||
90 | exit(EXIT_SUCCESS); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | try { | ||
95 | FbTk::App app(displayname.c_str()); | ||
96 | if (app.display() == 0) { | ||
97 | cerr<<"Could not open display!"<<endl; | ||
98 | cerr<<"Make sure you have an X server running."<<endl; | ||
99 | throw string("Display connection"); | ||
100 | } | ||
101 | |||
102 | FbPager::FbPager fbpager(screen_num, withdraw, | ||
103 | fbhints, | ||
104 | ewmh, | ||
105 | show_resources, | ||
106 | layer, | ||
107 | resourcefile.c_str()); | ||
108 | if (!show_resources) | ||
109 | app.eventLoop(); | ||
110 | |||
111 | } catch (std::string err) { | ||
112 | cerr<<"Error: "<<err<<endl; | ||
113 | } catch (...) { | ||
114 | cerr<<"Unknown exception caught!"<<endl; | ||
115 | } | ||
116 | } | ||