aboutsummaryrefslogtreecommitdiff
path: root/src/main.cc
blob: 481b5f3be146ad72e2fbf2a5a831ed59abc20b8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// main.cc for FbPager
// Copyright (c) 2003-2004 Henrik Kinnunen (fluxgen at users.sourceforge.net)
// 
// 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.

// $Id$

#include "FbPager.hh"
#include "FbTk/App.hh"

#include <cstdlib>
#include <iostream>
#include <string>
#include <string.h>
#include "version.h"

using namespace std;

void showVersion() {
    cout<<"FbPager "<<__fbpager_version<<": (c) 2004-2007 Henrik Kinnunen (fluxgen<at>fluxbox org)"<<endl;
}

void showUsage(const char * const appname) {
    showVersion();
    cout<<"Usage: "<<endl
        <<appname<<" <argument>"<<endl
        <<"Arguments: "<<endl
        <<"  -display <displayname>"<<endl
        <<"  -w              withdrawn state (i.e in the Slit)"<<endl
        <<"  -rc <filename>  resource file (default: ~/.fluxbox/fbpager)"<<endl
        <<"  -sr             show resources"<<endl
        <<"  -s <screen number> (default: 0)"<<endl
        <<"  -v              show version"<<endl
        <<"  -h              show this help"<<endl
        <<"  -l <layer>       layer, values: top or bottom" << endl;
}

int main(int argc, char **argv) {
    int screen_num = 0;
    std::string displayname;
    bool withdraw = false;
    std::string resourcefile("~/.fluxbox/fbpager");
    bool ewmh = true;
    bool fbhints = true;
    bool show_resources = false;
    int layer = -1;
    for (int arg = 1; arg < argc; ++arg) {
        string sarg = argv[arg];
        // if argument starts with "--" remove the first '-'
        if (sarg[0] == '-' && sarg[1] == '-')
            sarg.erase(0, 1);

        if (sarg == "-display" && arg < argc - 1) {
            displayname = argv[++arg];
        } else if (sarg == "-w")
            withdraw = true;
        else if (sarg == "-rc" && arg < argc - 1)
            resourcefile = argv[++arg];
        else if (sarg == "-v") {
            showVersion();
            exit(EXIT_SUCCESS);
        } else if (sarg == "-s" && arg < argc - 1) {
            screen_num = atoi(argv[++arg]);
        } else if (sarg == "-sr") {
            show_resources = true;
        } else if (sarg == "-l") {
            ++arg;
            if (strcmp(argv[arg], "top")== 0) {
                layer = 2;
            } else if (strcmp(argv[arg], "bottom") == 0) {
                layer = 0;
            }
        } else {
            showUsage(argv[0]);
            exit(EXIT_SUCCESS);
        }
    }

    try {
        FbTk::App app(displayname.c_str());
        if (app.display() == 0) {
            cerr<<"Could not open display!"<<endl;
            cerr<<"Make sure you have an X server running."<<endl;
            throw string("Display connection");
        }

        FbPager::FbPager fbpager(screen_num, withdraw, 
                                 fbhints,
                                 ewmh,
                                 show_resources,
                                 layer,
                                 resourcefile.c_str());
        if (!show_resources)
            app.eventLoop();

    } catch (std::string err) {
        cerr<<"Error: "<<err<<endl;
    } catch (...) {
        cerr<<"Unknown exception caught!"<<endl;
    }
}