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, move_00);
122 ACTION("top-middle (3x2 grid)", Y, move_10);
123 ACTION("top-right (3x2 grid)", U, move_20);
124 ACTION("bottom-left (3x2 grid)", G, move_01);
125 ACTION("bottom-middle (3x2 grid)", H, move_11);
126 ACTION("bottom-right (3x2 grid)", J, move_21);
129 #define ACTION(size, key, slot) \
130 KAction * slot = new KAction(winGrid); \
131 actions->addAction("Resize " size, slot); \
132 slot->setHelpText("Resize " size); \
133 slot->setGlobalShortcut(KShortcut( \
134 Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_ ## key, Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_ ## key)); \
135 QObject::connect(slot, SIGNAL(triggered(bool)), winGrid, SLOT(slot()));
137 ACTION("quarter", I, resize_Q);
139 ACTION("horizontal", O, resize_H);
140 ACTION("vertical", K, resize_V);
141 ACTION("full", L, resize_F);
143 ACTION("top-left (3x2 grid)", T, resize_00);
144 ACTION("top-middle (3x2 grid)", Y, resize_10);
145 ACTION("top-right (3x2 grid)", U, resize_20);
146 ACTION("bottom-left (3x2 grid)", G, resize_01);
147 ACTION("bottom-middle (3x2 grid)", H, resize_11);
148 ACTION("bottom-right (3x2 grid)", J, resize_21);
151 #define ACTION(dir, key, slot) \
152 KAction * slot = new KAction(winGrid); \
153 actions->addAction("Move " dir, slot); \
154 slot->setHelpText("Move " dir); \
155 slot->setGlobalShortcut(KShortcut( \
156 Qt::ALT+Qt::SHIFT+Qt::Key_ ## key, Qt::META+Qt::SHIFT+Qt::Key_ ## key)); \
157 QObject::connect(slot, SIGNAL(triggered(bool)), winGrid, SLOT(slot()));
159 ACTION("left", Left, move_L);
160 ACTION("right", Right, move_R);
161 ACTION("up", Up, move_U);
162 ACTION("down", Down, move_D);
165 #define ACTION(resize, key, slot) \
166 KAction * slot = new KAction(winGrid); \
167 actions->addAction(resize " size", slot); \
168 slot->setHelpText(resize " size"); \
169 slot->setGlobalShortcut(KShortcut( \
170 Qt::ALT+Qt::CTRL+Qt::SHIFT+Qt::Key_ ## key,Qt::META+Qt::CTRL+Qt::SHIFT+Qt::Key_ ## key)); \
171 QObject::connect(slot, SIGNAL(triggered(bool)), winGrid, SLOT(slot()));
173 ACTION("Increase horizontal", Right, resize_IH);
174 ACTION("Increase vertical", Down, resize_IV);
175 ACTION("Decrease horizontal", Left, resize_DH);
176 ACTION("Decrease vertical", Up, resize_DV);
180 int ret = app->exec();