Implement reserve-north/south/west/east
[kwingrid.git] / main.cc
1 #include <iostream>
2 #include <kuniqueapplication.h>
3 #include <klocale.h>
4 #include <kcmdlineargs.h>
5 #include <kaboutdata.h>
6 #include <kdebug.h>
7 #include <kglobalaccel.h>
8 #include <kactioncollection.h>
9
10 #include "kwingrid.h"
11
12 /* Die optimalen werte für hgap und vgap berechnen sich zu:
13  *
14  * gap = size%split + n*split
15  *
16  * für n = 0,1,2,... und size die Bildschirmgröße in der jeweiligen Richtung
17  */
18
19 int main(int argc, char **argv)
20 {
21     KAboutData * aboutdata = new KAboutData("kwingrid",
22                                             "KWinGrid",
23                                             ki18n("Window Grid"),
24                                             "0.1",
25                                             KLocalizedString(),
26                                             KAboutData::License_GPL,
27                                             ki18n("(C) 1999,2000,2002,2004 Stefan Bund"));
28     aboutdata->addAuthor(ki18n("Stefan Bund"),ki18n("Developer"),"stefab@j32.de",
29                          "http://www.j32.de");
30
31     KCmdLineOptions winGridOpts;
32     winGridOpts.add("split <width>", ki18n("split"), 0);
33     winGridOpts.add("ignorestruts <screen>", ki18n("ignorestruts"), "");
34     winGridOpts.add("reserve-north <n>", ki18n("reserve north"), "");
35     winGridOpts.add("reserve-south <n>", ki18n("reserve south"), "");
36     winGridOpts.add("reserve-west <n>", ki18n("reserve west"), "");
37     winGridOpts.add("reserve-east <n>", ki18n("reserve east"), "");
38     winGridOpts.add("+hgap", ki18n("hgap"), 0);
39     winGridOpts.add("+vgap", ki18n("vgap"), 0);
40     winGridOpts.add("+hsplit", ki18n("hsplit"), 0);
41     winGridOpts.add("+vsplit", ki18n("vsplit"), 0);
42
43     KCmdLineArgs::init(argc, argv, aboutdata);
44     KCmdLineArgs::addCmdLineOptions(winGridOpts);
45     KUniqueApplication::addCmdLineOptions();
46
47     if (! KUniqueApplication::start()) {
48         kdError() << "KWinGrid is already running!" << endl;
49         return 0;
50     }
51
52     KApplication * app = new KUniqueApplication;
53     KCmdLineArgs * args = KCmdLineArgs::parsedArgs();
54
55     if (args->count()!=4) {
56         kdError() << "Invalid arguments. Try --help\n";
57         return 0;
58     }
59
60     int split = 0;
61     int ignorestruts = -1;
62     if (args->isSet("split"))
63         split = args->getOption("split").toInt();
64
65     if (args->isSet("ignorestruts"))
66         ignorestruts = args->getOption("ignorestruts").toInt();
67
68     if (args->count() != 4) {
69         std::cerr << "invalid number of arguments" << std::endl;
70         return 1;
71     }
72
73     int rn = 0;
74     int rs = 0;
75     int re = 0;
76     int rw = 0;
77
78     if (args->isSet("reserve-north"))
79         rn = args->getOption("reserve-north").toInt();
80     if (args->isSet("reserve-south"))
81         rs = args->getOption("reserve-south").toInt();
82     if (args->isSet("reserve-west"))
83         rw = args->getOption("reserve-west").toInt();
84     if (args->isSet("reserve-east"))
85         re = args->getOption("reserve-east").toInt();
86
87     int hgap = args->arg(0).toInt();
88     int vgap = args->arg(1).toInt();
89     int hsplit = args->arg(2).toInt();
90     int vsplit = args->arg(3).toInt();
91
92     args->clear();
93
94     KWinGrid * winGrid = new KWinGrid(hgap,vgap,hsplit,vsplit,split,ignorestruts,
95                                       rn, rs, rw, re);
96
97     KActionCollection * actions = new KActionCollection(winGrid);
98
99     KAction * move_TL = new KAction(winGrid);
100     actions->addAction("Move top-left", move_TL);
101     move_TL->setHelpText("Move active window top-left");
102     move_TL->setGlobalShortcut(KShortcut(
103         Qt::ALT+Qt::SHIFT+Qt::Key_I, Qt::META+Qt::SHIFT+Qt::Key_I));
104     QObject::connect(move_TL, SIGNAL(triggered(bool)), winGrid, SLOT(move_TL()));
105
106     KAction * move_TR = new KAction(winGrid);
107     actions->addAction("Move top-right", move_TR);
108     move_TR->setHelpText("Move active window top-right");
109     move_TR->setGlobalShortcut(KShortcut(
110         Qt::ALT+Qt::SHIFT+Qt::Key_O, Qt::META+Qt::SHIFT+Qt::Key_O));
111     QObject::connect(move_TR, SIGNAL(triggered(bool)), winGrid, SLOT(move_TR()));
112
113     KAction * move_BL = new KAction(winGrid);
114     actions->addAction("Move bottom-left", move_BL);
115     move_BL->setHelpText("Move active window bottom-left");
116     move_BL->setGlobalShortcut(KShortcut(
117         Qt::ALT+Qt::SHIFT+Qt::Key_K, Qt::META+Qt::SHIFT+Qt::Key_K));
118     QObject::connect(move_BL, SIGNAL(triggered(bool)), winGrid, SLOT(move_BL()));
119
120     KAction * move_BR = new KAction(winGrid);
121     actions->addAction("Move bottom-right", move_BR);
122     move_BR->setHelpText("Move active window bottom-right");
123     move_BR->setGlobalShortcut(KShortcut(
124         Qt::ALT+Qt::SHIFT+Qt::Key_L, Qt::META+Qt::SHIFT+Qt::Key_L));
125     QObject::connect(move_BR, SIGNAL(triggered(bool)), winGrid, SLOT(move_BR()));
126
127     KAction * resize_Q = new KAction(winGrid);
128     actions->addAction("Resize quarter", resize_Q);
129     resize_Q->setHelpText("Resize quarter");
130     resize_Q->setGlobalShortcut(KShortcut(
131         Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_I, Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_I));
132     QObject::connect(resize_Q, SIGNAL(triggered(bool)), winGrid, SLOT(resize_Q()));
133
134     KAction * resize_H = new KAction(winGrid);
135     actions->addAction("Resize horizontal", resize_H);
136     resize_H->setHelpText("Resize horizontal");
137     resize_H->setGlobalShortcut(KShortcut(
138         Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_O, Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_O));
139     QObject::connect(resize_H, SIGNAL(triggered(bool)), winGrid, SLOT(resize_H()));
140
141     KAction * resize_V = new KAction(winGrid);
142     actions->addAction("Resize vertical", resize_V);
143     resize_V->setHelpText("Resize vertical");
144     resize_V->setGlobalShortcut(KShortcut(
145         Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_K, Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_K));
146     QObject::connect(resize_V, SIGNAL(triggered(bool)), winGrid, SLOT(resize_V()));
147
148     KAction * resize_F = new KAction(winGrid);
149     actions->addAction("Resize full", resize_F);
150     resize_F->setHelpText("Resize full");
151     resize_F->setGlobalShortcut(KShortcut(
152         Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_L, Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_L));
153     QObject::connect(resize_F, SIGNAL(triggered(bool)), winGrid, SLOT(resize_F()));
154
155     KAction * move_L = new KAction(winGrid);
156     actions->addAction("Move left", move_L);
157     move_L->setHelpText("Move left");
158     move_L->setGlobalShortcut(KShortcut(
159         Qt::ALT+Qt::SHIFT+Qt::Key_Left, Qt::META+Qt::SHIFT+Qt::Key_Left));
160     QObject::connect(move_L, SIGNAL(triggered(bool)), winGrid, SLOT(move_L()));
161
162     KAction * move_R = new KAction(winGrid);
163     actions->addAction("Move right", move_R);
164     move_R->setHelpText("Move right");
165     move_R->setGlobalShortcut(KShortcut(
166         Qt::ALT+Qt::SHIFT+Qt::Key_Right, Qt::META+Qt::SHIFT+Qt::Key_Right));
167     QObject::connect(move_R, SIGNAL(triggered(bool)), winGrid, SLOT(move_R()));
168
169     KAction * move_U = new KAction(winGrid);
170     actions->addAction("Move up", move_U);
171     move_U->setHelpText("Move up");
172     move_U->setGlobalShortcut(KShortcut(
173         Qt::ALT+Qt::SHIFT+Qt::Key_Up, Qt::META+Qt::SHIFT+Qt::Key_Up));
174     QObject::connect(move_U, SIGNAL(triggered(bool)), winGrid, SLOT(move_U()));
175
176     KAction * move_D = new KAction(winGrid);
177     actions->addAction("Move down", move_D);
178     move_D->setHelpText("Move down");
179     move_D->setGlobalShortcut(KShortcut(
180         Qt::ALT+Qt::SHIFT+Qt::Key_Down, Qt::META+Qt::SHIFT+Qt::Key_Down));
181     QObject::connect(move_D, SIGNAL(triggered(bool)), winGrid, SLOT(move_D()));
182
183     KAction * resize_IH = new KAction(winGrid);
184     actions->addAction("Increase horizontal size", resize_IH);
185     resize_IH->setHelpText("Increase horizontal size");
186     resize_IH->setGlobalShortcut(KShortcut(
187         Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_Right,Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_Right));
188     QObject::connect(resize_IH, SIGNAL(triggered(bool)), winGrid, SLOT(resize_IH()));
189
190     KAction * resize_IV = new KAction(winGrid);
191     actions->addAction("Increase vertical size", resize_IV);
192     resize_IV->setHelpText("Increase vertical size");
193     resize_IV->setGlobalShortcut(KShortcut(
194         Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_Down,Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_Down));
195     QObject::connect(resize_IV, SIGNAL(triggered(bool)), winGrid, SLOT(resize_IV()));
196
197     KAction * resize_DH = new KAction(winGrid);
198     actions->addAction("Decrease horizontal size", resize_DH);
199     resize_DH->setHelpText("Decrease horizontal size");
200     resize_DH->setGlobalShortcut(KShortcut(
201         Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_Left,Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_Left));
202     QObject::connect(resize_DH, SIGNAL(triggered(bool)), winGrid, SLOT(resize_DH()));
203
204     KAction * resize_DV = new KAction(winGrid);
205     actions->addAction("Decrease vertical size", resize_DV);
206     resize_DV->setHelpText("Decrease vertical size");
207     resize_DV->setGlobalShortcut(KShortcut(
208         Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_Up,Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_Up));
209     QObject::connect(resize_DV, SIGNAL(triggered(bool)), winGrid, SLOT(resize_DV()));
210
211     int ret = app->exec();
212
213     delete app;
214     return ret;
215 }
216