commit 56c02bd

Michael Forney  ·  2014-02-08 08:38:06 +0000 UTC
parent 81cee7d
xkb: Don't use unnecessary code-block
1 files changed,  +35, -39
+35, -39
 1@@ -91,7 +91,10 @@ void swc_xkb_finalize(struct swc_xkb * xkb)
 2 
 3 bool swc_xkb_update_keymap(struct swc_xkb * xkb)
 4 {
 5+    const char * keymap_directory = getenv("XDG_RUNTIME_DIR") ?: "/tmp";
 6     char * keymap_string;
 7+    char keymap_path[strlen(keymap_directory) + 1
 8+                     + sizeof keymap_file_template];
 9 
10     xkb->indices.ctrl
11         = xkb_keymap_mod_get_index(xkb->keymap.map, XKB_MOD_NAME_CTRL);
12@@ -102,55 +105,48 @@ bool swc_xkb_update_keymap(struct swc_xkb * xkb)
13     xkb->indices.shift
14         = xkb_keymap_mod_get_index(xkb->keymap.map, XKB_MOD_NAME_SHIFT);
15 
16-    /* Keymap string */
17-    {
18-        const char * keymap_directory = getenv("XDG_RUNTIME_DIR") ?: "/tmp";
19-        char keymap_path[strlen(keymap_directory) + 1
20-                         + sizeof keymap_file_template];
21-
22-        /* In order to send the keymap to clients, we must first convert it to a
23-         * string and then mmap it to a file. */
24-        keymap_string = xkb_keymap_get_as_string(xkb->keymap.map,
25-                                                 XKB_KEYMAP_FORMAT_TEXT_V1);
26+    /* In order to send the keymap to clients, we must first convert it to a
27+     * string and then mmap it to a file. */
28+    keymap_string = xkb_keymap_get_as_string(xkb->keymap.map,
29+                                             XKB_KEYMAP_FORMAT_TEXT_V1);
30 
31-        if (!keymap_string)
32-        {
33-            printf("could not get XKB keymap as a string\n");
34-            goto error0;
35-        }
36+    if (!keymap_string)
37+    {
38+        printf("could not get XKB keymap as a string\n");
39+        goto error0;
40+    }
41 
42-        sprintf(keymap_path, "%s/%s", keymap_directory, keymap_file_template);
43+    sprintf(keymap_path, "%s/%s", keymap_directory, keymap_file_template);
44 
45-        xkb->keymap.size = strlen(keymap_string) + 1;
46-        xkb->keymap.fd = mkostemp(keymap_path, O_CLOEXEC);
47+    xkb->keymap.size = strlen(keymap_string) + 1;
48+    xkb->keymap.fd = mkostemp(keymap_path, O_CLOEXEC);
49 
50-        if (xkb->keymap.fd == -1)
51-        {
52-            printf("could not create XKB keymap file\n");
53-            goto error1;
54-        }
55+    if (xkb->keymap.fd == -1)
56+    {
57+        printf("could not create XKB keymap file\n");
58+        goto error1;
59+    }
60 
61-        unlink(keymap_path);
62+    unlink(keymap_path);
63 
64-        if (posix_fallocate(xkb->keymap.fd, 0, xkb->keymap.size) != 0)
65-        {
66-            printf("could not resize XKB keymap file\n");
67-            goto error2;
68-        }
69+    if (posix_fallocate(xkb->keymap.fd, 0, xkb->keymap.size) != 0)
70+    {
71+        printf("could not resize XKB keymap file\n");
72+        goto error2;
73+    }
74 
75-        xkb->keymap.area = mmap(NULL, xkb->keymap.size, PROT_READ | PROT_WRITE,
76-            MAP_SHARED, xkb->keymap.fd, 0);
77+    xkb->keymap.area = mmap(NULL, xkb->keymap.size, PROT_READ | PROT_WRITE,
78+        MAP_SHARED, xkb->keymap.fd, 0);
79 
80-        if (xkb->keymap.area == MAP_FAILED)
81-        {
82-            printf("could not mmap XKB keymap string\n");
83-            goto error2;
84-        }
85+    if (xkb->keymap.area == MAP_FAILED)
86+    {
87+        printf("could not mmap XKB keymap string\n");
88+        goto error2;
89+    }
90 
91-        strcpy(xkb->keymap.area, keymap_string);
92+    strcpy(xkb->keymap.area, keymap_string);
93 
94-        free(keymap_string);
95-    }
96+    free(keymap_string);
97 
98     return true;
99