1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
2 | * |
3 | * Copyright (C) 2014 Red Hat, Inc. |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify |
6 | * it under the terms of the GNU Lesser General Public License as published |
7 | * by the Free Software Foundation; either version 2 of the License, or |
8 | * (at your option) any later version. |
9 | * |
10 | * This program is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | * GNU Lesser General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Lesser General Public License |
16 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
17 | * |
18 | * Author: Florian Müllner <fmuellner@gnome.org> |
19 | */ |
20 | |
21 | #include <stdio.h> |
22 | #include <string.h> |
23 | #include <glib.h> |
24 | |
25 | #include "wm-button-layout-translation.h" |
26 | |
27 | static void |
28 | translate_buttons (char *layout, int *len_p) |
29 | { |
30 | char *strp = layout, *button; |
31 | int len = 0; |
32 | |
33 | if (!layout || !*layout) |
34 | goto out; |
35 | |
36 | while ((button = strsep (stringp: &strp, delim: "," ))) |
37 | { |
38 | const char *gtkbutton; |
39 | |
40 | if (strcmp (s1: button, s2: "menu" ) == 0) |
41 | gtkbutton = "icon" ; |
42 | else if (strcmp (s1: button, s2: "appmenu" ) == 0) |
43 | gtkbutton = "menu" ; |
44 | else if (strcmp (s1: button, s2: "minimize" ) == 0) |
45 | gtkbutton = "minimize" ; |
46 | else if (strcmp (s1: button, s2: "maximize" ) == 0) |
47 | gtkbutton = "maximize" ; |
48 | else if (strcmp (s1: button, s2: "close" ) == 0) |
49 | gtkbutton = "close" ; |
50 | else |
51 | continue; |
52 | |
53 | if (len) |
54 | layout[len++] = ','; |
55 | |
56 | strcpy (dest: layout + len, src: gtkbutton); |
57 | len += strlen (s: gtkbutton); |
58 | } |
59 | layout[len] = '\0'; |
60 | |
61 | out: |
62 | if (len_p) |
63 | *len_p = len; |
64 | } |
65 | |
66 | void |
67 | translate_wm_button_layout_to_gtk (char *layout) |
68 | { |
69 | char *strp = layout, *left_buttons, *right_buttons; |
70 | int left_len, right_len = 0; |
71 | |
72 | left_buttons = strsep (stringp: &strp, delim: ":" ); |
73 | right_buttons = strp; |
74 | |
75 | translate_buttons (layout: left_buttons, len_p: &left_len); |
76 | memmove (dest: layout, src: left_buttons, n: left_len); |
77 | |
78 | if (strp == NULL) |
79 | goto out; /* no ":" in layout */ |
80 | |
81 | layout[left_len++] = ':'; |
82 | |
83 | translate_buttons (layout: right_buttons, len_p: &right_len); |
84 | memmove (dest: layout + left_len, src: right_buttons, n: right_len); |
85 | |
86 | out: |
87 | layout[left_len + right_len] = '\0'; |
88 | } |
89 | |