aboutsummaryrefslogtreecommitdiff
path: root/util/fluxbox-update_configs.cc
diff options
context:
space:
mode:
authormarkt <markt>2007-02-09 18:13:01 (GMT)
committermarkt <markt>2007-02-09 18:13:01 (GMT)
commit6fdda1a31d2417c23f5f222114d30ce6abec8b40 (patch)
tree929a0c0a5ffac232568011ef055934354f4367da /util/fluxbox-update_configs.cc
parent93d8310c0c51fe1edcdfa5240f724ab6306ce92a (diff)
downloadfluxbox-6fdda1a31d2417c23f5f222114d30ce6abec8b40.zip
fluxbox-6fdda1a31d2417c23f5f222114d30ce6abec8b40.tar.bz2
added mouse bindings to the keys file
Diffstat (limited to 'util/fluxbox-update_configs.cc')
-rw-r--r--util/fluxbox-update_configs.cc197
1 files changed, 197 insertions, 0 deletions
diff --git a/util/fluxbox-update_configs.cc b/util/fluxbox-update_configs.cc
new file mode 100644
index 0000000..de1fbb9
--- /dev/null
+++ b/util/fluxbox-update_configs.cc
@@ -0,0 +1,197 @@
1// fluxbox-update_configs.cc
2// Copyright (c) 2007 Fluxbox Team (fluxgen at fluxbox dot org)
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#include "../src/FbTk/I18n.hh"
23#include "../src/FbTk/Resource.hh"
24#include "../src/FbTk/StringUtil.hh"
25
26#include "../src/defaults.hh"
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif // HAVE_CONFIG_H
31
32#ifdef HAVE_SIGNAL_H
33#include <signal.h>
34#endif // HAVE_SIGNAL_H
35
36//use GNU extensions
37#ifndef _GNU_SOURCE
38#define _GNU_SOURCE
39#endif // _GNU_SOURCE
40
41#ifdef HAVE_CSTDIO
42 #include <cstdio>
43#else
44 #include <stdio.h>
45#endif
46#ifdef HAVE_CSTDLIB
47 #include <cstdlib>
48#else
49 #include <stdlib.h>
50#endif
51#ifdef HAVE_CSTRING
52 #include <cstring>
53#else
54 #include <string.h>
55#endif
56#include <iostream>
57#include <fstream>
58
59using std::cout;
60using std::cerr;
61using std::endl;
62using std::string;
63using std::ifstream;
64using std::ofstream;
65
66#define VERSION 1
67
68int run_updates(int old_version, FbTk::ResourceManager rm) {
69 int new_version = old_version;
70
71 if (old_version < 1) { // add mouse events to keys file
72 FbTk::Resource<string> rc_keyfile(rm, DEFAULTKEYSFILE,
73 "session.keyFile", "Session.KeyFile");
74 string keyfilename = FbTk::StringUtil::expandFilename(*rc_keyfile);
75
76 // ok, I don't know anything about file handling in c++
77 // what's it to you?!?!
78 // I assume there should be some error handling in here, but I sure
79 // don't know how, and I don't have documentation
80
81 ifstream in_keyfile(keyfilename.c_str());
82 string whole_keyfile = "";
83
84 while (!in_keyfile.eof()) {
85 string linebuffer;
86
87 getline(in_keyfile, linebuffer);
88 whole_keyfile += linebuffer + "\n";
89 }
90 in_keyfile.close();
91
92 ofstream out_keyfile(keyfilename.c_str());
93 // let's put our new keybindings first, so they're easy to find
94 out_keyfile << "!mouse actions added by fluxbox-update_configs" << endl
95 << "OnDesktop Mouse1 :hideMenus" << endl
96 << "OnDesktop Mouse2 :workspaceMenu" << endl
97 << "OnDesktop Mouse3 :rootMenu" << endl;
98
99 // scrolling on desktop needs to match user's desktop wheeling settings
100 // hmmm, what are the odds that somebody wants this to be different on
101 // different screens? the ability is going away until we make per-screen
102 // keys files, anyway, so let's just use the first screen's setting
103 FbTk::Resource<bool> rc_wheeling(rm, true,
104 "session.screen0.desktopwheeling",
105 "Session.Screen0.DesktopWheeling");
106 FbTk::Resource<bool> rc_reverse(rm, false,
107 "session.screen0.reversewheeling",
108 "Session.Screen0.ReverseWheeling");
109 if (*rc_wheeling) {
110 if (*rc_reverse) { // if you ask me, this should have been default
111 out_keyfile << "OnDesktop Mouse4 :prevWorkspace" << endl
112 << "OnDesktop Mouse5 :nextWorkspace" << endl;
113 } else {
114 out_keyfile << "OnDesktop Mouse4 :nextWorkspace" << endl
115 << "OnDesktop Mouse5 :prevWorkspace" << endl;
116 }
117 }
118 out_keyfile << endl; // just for good looks
119
120 // now, restore user's old keybindings
121 out_keyfile << whole_keyfile;
122 new_version = 1;
123 }
124
125 return new_version;
126}
127
128int main(int argc, char **argv) {
129 string rc_filename;
130 int i = 1;
131 pid_t fb_pid = 0;
132
133 FbTk::NLSInit("fluxbox.cat");
134 _FB_USES_NLS;
135
136 for (; i < argc; i++) {
137 if (strcmp(argv[i], "-rc") == 0) {
138 // look for alternative rc file to use
139
140 if ((++i) >= argc) {
141 cerr<<_FB_CONSOLETEXT(main, RCRequiresArg,
142 "error: '-rc' requires an argument", "the -rc option requires a file argument")<<endl;
143 exit(1);
144 }
145
146 rc_filename = argv[i];
147 } else if (strcmp(argv[i], "-pid") == 0) {
148 if ((++i) >= argc) {
149 // need translations for this, too
150 cerr<<"the -pid option requires a numeric argument"<<endl;
151 } else
152 fb_pid = atoi(argv[i]);
153 } else if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) {
154 // no NLS translations yet -- we'll just have to use English for now
155 cout << " -rc <string>\t\t\tuse alternate resource file.\n"
156 << " -pid <int>\t\t\ttell fluxbox to reload configuration.\n"
157 << " -help\t\t\t\tdisplay this help text and exit.\n\n"
158 << endl;
159 exit(0);
160 }
161 }
162
163 FbTk::ResourceManager resource_manager(rc_filename.c_str(),false);
164 if (rc_filename.empty() || !resource_manager.load(rc_filename.c_str())) {
165 // couldn't load rc file
166 if (!rc_filename.empty()) {
167 cerr<<_FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database", "Failed trying to read rc file")<<":"<<rc_filename<<endl;
168 cerr<<_FB_CONSOLETEXT(Fluxbox, CantLoadRCFileTrying, "Retrying with", "Retrying rc file loading with (the following file)")<<": "<<DEFAULT_INITFILE<<endl;
169 }
170 // couldn't load default rc file, either
171 if (!resource_manager.load(DEFAULT_INITFILE)) {
172 cerr<<_FB_CONSOLETEXT(Fluxbox, CantLoadRCFile, "Failed to load database", "")<<": "<<DEFAULT_INITFILE<<endl;
173 exit(1); // this is a fatal error for us
174 }
175 }
176
177 // run updates here
178 // I feel like putting this in a separate function for no apparent reason
179
180 FbTk::Resource<int> config_version(resource_manager, 0,
181 "session.configVersion", "Session.ConfigVersion");
182 int old_version = *config_version;
183 int new_version = run_updates(old_version, resource_manager);
184 if (new_version > old_version) {
185 config_version = new_version;
186 resource_manager.save(rc_filename.c_str(), rc_filename.c_str());
187
188#ifdef HAVE_SIGNAL_H
189 // if we were given a fluxbox pid, send it a reconfigure signal
190 if (fb_pid > 0)
191 kill(fb_pid, SIGUSR2);
192#endif // HAVE_SIGNAL_H
193
194 }
195
196 return 0;
197}