2 #include <kuniqueapplication.h>
4 #include <kcmdlineargs.h>
5 #include <kaboutdata.h>
7 #include <kglobalaccel.h>
8 #include <kactioncollection.h>
12 /* Die optimalen werte für hgap und vgap berechnen sich zu:
14 * gap = size%split + n*split
16 * für n = 0,1,2,... und size die Bildschirmgröße in der jeweiligen Richtung
19 int main(int argc, char **argv)
21 KAboutData * aboutdata = new KAboutData("kwingrid",
26 KAboutData::License_GPL,
27 ki18n("(C) 1999,2000,2002,2004 Stefan Bund"));
28 aboutdata->addAuthor(ki18n("Stefan Bund"),ki18n("Developer"),"stefab@j32.de",
31 KCmdLineOptions winGridOpts;
32 winGridOpts.add("split <width>", ki18n("split"), 0);
33 winGridOpts.add("ignorestruts <screen>", ki18n("ignorestruts. -1 = all screens"), "");
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("southstrut <n>", ki18n("set south strut size"), "");
39 winGridOpts.add("strutscreen <n>", ki18n("set screen to apply manual strut to. -1 = all screens"), "");
40 winGridOpts.add("+hgap", ki18n("hgap"), 0);
41 winGridOpts.add("+vgap", ki18n("vgap"), 0);
42 winGridOpts.add("+hsplit", ki18n("hsplit"), 0);
43 winGridOpts.add("+vsplit", ki18n("vsplit"), 0);
45 KCmdLineArgs::init(argc, argv, aboutdata);
46 KCmdLineArgs::addCmdLineOptions(winGridOpts);
47 KUniqueApplication::addCmdLineOptions();
49 if (! KUniqueApplication::start()) {
50 kdError() << "KWinGrid is already running!" << endl;
54 KApplication * app = new KUniqueApplication;
55 KCmdLineArgs * args = KCmdLineArgs::parsedArgs();
57 if (args->count()!=4) {
58 kdError() << "Invalid arguments. Try --help\n";
63 int ignorestruts = -2;
64 if (args->isSet("split"))
65 split = args->getOption("split").toInt();
67 if (args->isSet("ignorestruts"))
68 ignorestruts = args->getOption("ignorestruts").toInt();
70 if (args->count() != 4) {
71 std::cerr << "invalid number of arguments" << std::endl;
77 if (args->isSet("southstrut"))
78 southstrut = args->getOption("southstrut").toInt();
79 if (args->isSet("strutscreen"))
80 strutscreen = args->getOption("strutscreen").toInt();
87 if (args->isSet("reserve-north"))
88 rn = args->getOption("reserve-north").toInt();
89 if (args->isSet("reserve-south"))
90 rs = args->getOption("reserve-south").toInt();
91 if (args->isSet("reserve-west"))
92 rw = args->getOption("reserve-west").toInt();
93 if (args->isSet("reserve-east"))
94 re = args->getOption("reserve-east").toInt();
96 int hgap = args->arg(0).toInt();
97 int vgap = args->arg(1).toInt();
98 int hsplit = args->arg(2).toInt();
99 int vsplit = args->arg(3).toInt();
103 KWinGrid * winGrid = new KWinGrid(hgap,vgap,hsplit,vsplit,split,ignorestruts,
104 rn, rs, rw, re, southstrut, strutscreen);
106 KActionCollection * actions = new KActionCollection(winGrid);
108 #define ACTION(pos, key, slot) \
109 KAction * slot = new KAction(winGrid); \
110 actions->addAction("Move " pos, slot); \
111 slot->setHelpText("Move active window" pos); \
112 slot->setGlobalShortcut(KShortcut( \
113 Qt::ALT+Qt::SHIFT+Qt::Key_ ## key, Qt::META+Qt::SHIFT+Qt::Key_ ## key)); \
114 QObject::connect(slot, SIGNAL(triggered(bool)), winGrid, SLOT(slot()))
116 ACTION("top-left", I, move_TL);
117 ACTION("top-right", O, move_TR);
118 ACTION("bottom-left", K, move_BL);
119 ACTION("bottom-right", L, move_BR);
121 ACTION("top-left (3x2 grid)", T, move32_00);
122 ACTION("top-middle (3x2 grid)", Y, move32_10);
123 ACTION("top-right (3x2 grid)", U, move32_20);
124 ACTION("bottom-left (3x2 grid)", G, move32_01);
125 ACTION("bottom-middle (3x2 grid)", H, move32_11);
126 ACTION("bottom-right (3x2 grid)", J, move32_21);
128 ACTION(" 0,0 (4x3 grid)", Q, move43_00);
129 ACTION(" 1,0 (4x3 grid)", W, move43_10);
130 ACTION(" 2,0 (4x3 grid)", E, move43_20);
131 ACTION(" 3,0 (4x3 grid)", R, move43_30);
132 ACTION(" 0,1 (4x3 grid)", A, move43_01);
133 ACTION(" 1,1 (4x3 grid)", S, move43_11);
134 ACTION(" 2,1 (4x3 grid)", D, move43_21);
135 ACTION(" 3,1 (4x3 grid)", F, move43_31);
136 ACTION(" 0,2 (4x3 grid)", Z, move43_02);
137 ACTION(" 1,2 (4x3 grid)", X, move43_12);
138 ACTION(" 2,2 (4x3 grid)", C, move43_22);
139 ACTION(" 3,2 (4x3 grid)", V, move43_32);
143 #define ACTION(pos, key, slot) \
144 KAction * slot = new KAction(winGrid); \
145 actions->addAction("Move to Screen " pos, slot); \
146 slot->setHelpText("Move to Screen " pos); \
147 slot->setGlobalShortcut(KShortcut( \
148 Qt::ALT+Qt::SHIFT+Qt::Key_ ## key, Qt::META+Qt::SHIFT+Qt::Key_ ## key)); \
149 QObject::connect(slot, SIGNAL(triggered(bool)), winGrid, SLOT(slot()))
151 ACTION("0", B, move_Screen0);
152 ACTION("1", M, move_Screen1);
155 #define ACTION(size, key, slot) \
156 KAction * slot = new KAction(winGrid); \
157 actions->addAction("Resize " size, slot); \
158 slot->setHelpText("Resize " size); \
159 slot->setGlobalShortcut(KShortcut( \
160 Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_ ## key, Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_ ## key)); \
161 QObject::connect(slot, SIGNAL(triggered(bool)), winGrid, SLOT(slot()));
163 ACTION("quarter", I, resize_Q);
165 ACTION("horizontal", O, resize_H);
166 ACTION("vertical", K, resize_V);
167 ACTION("full", L, resize_F);
169 ACTION("top-left (3x2 grid)", T, resize32_00);
170 ACTION("top-middle (3x2 grid)", Y, resize32_10);
171 ACTION("top-right (3x2 grid)", U, resize32_20);
172 ACTION("bottom-left (3x2 grid)", G, resize32_01);
173 ACTION("bottom-middle (3x2 grid)", H, resize32_11);
174 ACTION("bottom-right (3x2 grid)", J, resize32_21);
176 ACTION(" 0,0 (4x3 grid)", Q, resize43_00);
177 ACTION(" 1,0 (4x3 grid)", W, resize43_10);
178 ACTION(" 2,0 (4x3 grid)", E, resize43_20);
179 ACTION(" 3,0 (4x3 grid)", R, resize43_30);
180 ACTION(" 0,1 (4x3 grid)", A, resize43_01);
181 ACTION(" 1,1 (4x3 grid)", S, resize43_11);
182 ACTION(" 2,1 (4x3 grid)", D, resize43_21);
183 ACTION(" 3,1 (4x3 grid)", F, resize43_31);
184 ACTION(" 0,2 (4x3 grid)", Z, resize43_02);
185 ACTION(" 1,2 (4x3 grid)", X, resize43_12);
186 ACTION(" 2,2 (4x3 grid)", C, resize43_22);
187 ACTION(" 3,2 (4x3 grid)", V, resize43_32);
190 #define ACTION(dir, key, slot) \
191 KAction * slot = new KAction(winGrid); \
192 actions->addAction("Move " dir, slot); \
193 slot->setHelpText("Move " dir); \
194 slot->setGlobalShortcut(KShortcut( \
195 Qt::ALT+Qt::SHIFT+Qt::Key_ ## key, Qt::META+Qt::SHIFT+Qt::Key_ ## key)); \
196 QObject::connect(slot, SIGNAL(triggered(bool)), winGrid, SLOT(slot()));
198 ACTION("left", Left, move_L);
199 ACTION("right", Right, move_R);
200 ACTION("up", Up, move_U);
201 ACTION("down", Down, move_D);
204 #define ACTION(resize, key, slot) \
205 KAction * slot = new KAction(winGrid); \
206 actions->addAction(resize " size", slot); \
207 slot->setHelpText(resize " size"); \
208 slot->setGlobalShortcut(KShortcut( \
209 Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_ ## key,Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_ ## key)); \
210 QObject::connect(slot, SIGNAL(triggered(bool)), winGrid, SLOT(slot()));
212 ACTION("Increase horizontal", Right, resize_IH);
213 ACTION("Increase vertical", Down, resize_IV);
214 ACTION("Decrease horizontal", Left, resize_DH);
215 ACTION("Decrease vertical", Up, resize_DV);
218 int ret = app->exec();