-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMappings.cpp
More file actions
71 lines (53 loc) · 1.43 KB
/
Mappings.cpp
File metadata and controls
71 lines (53 loc) · 1.43 KB
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
//
// Telescope - graphical task switcher
//
// (c) Ilya Skriblovsky, 2010
// <Ilya.Skriblovsky@gmail.com>
//
// $Id: Mappings.cpp 158 2011-02-22 20:05:07Z mitrandir $
#include "Mappings.h"
#include <string.h>
#include <stdlib.h>
#include "Mapping.h"
const char *mappingsFile = "/etc/telescope.keys";
Mappings::Mappings(Display *dpy)
:_dpy(dpy)
{
loadMappings();
}
void Mappings::loadMappings()
{
FILE *f = fopen(mappingsFile, "r");
if (! f)
fprintf(stderr, "Mappings file not found: %s\n", mappingsFile);
else
{
int lineNo = 1;
while (! feof(f))
{
char line[256];
const char *error;
if (fgets(line, sizeof(line), f) != 0)
{
Mapping *mapping = Mapping::parseMappingLine(_dpy, line, &error);
if (mapping)
_mappings.append(mapping);
else
if (error != 0)
fprintf(stderr, "Error parsing mapping file (line %d): %s\n", lineNo, error);
}
lineNo++;
}
fclose(f);
}
}
Mappings::~Mappings()
{
for (LinkedList<Mapping*>::Iter i = _mappings.head(); i; ++i)
delete (*i);
}
void Mappings::handleEvent(TeleWindow *teleWindow, Mapping::Event event, KeyCode keyCode)
{
for (LinkedList<Mapping*>::Iter i = _mappings.head(); i; ++i)
(*i)->handleEvent(teleWindow, event, keyCode);
}