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 General Public License as published by
7 * 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 General Public License for more details.
14 *
15 * You should have received a copy of the GNU 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
27static void
28translate_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 (&strp, ",")))
37 {
38 char *gtkbutton;
39
40 if (strcmp (button, "menu") == 0)
41 gtkbutton = "icon";
42 else if (strcmp (button, "appmenu") == 0)
43 gtkbutton = "menu";
44 else if (strcmp (button, "minimize") == 0)
45 gtkbutton = "minimize";
46 else if (strcmp (button, "maximize") == 0)
47 gtkbutton = "maximize";
48 else if (strcmp (button, "close") == 0)
49 gtkbutton = "close";
50 else
51 continue;
52
53 if (len)
54 layout[len++] = ',';
55
56 strcpy (layout + len, gtkbutton);
57 len += strlen (gtkbutton);
58 }
59 layout[len] = '\0';
60
61out:
62 if (len_p)
63 *len_p = len;
64}
65
66void
67translate_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 (&strp, ":");
73 right_buttons = strp;
74
75 translate_buttons (left_buttons, &left_len);
76 memmove (layout, left_buttons, left_len);
77
78 if (strp == NULL)
79 goto out; /* no ":" in layout */
80
81 layout[left_len++] = ':';
82
83 translate_buttons (right_buttons, &right_len);
84 memmove (layout + left_len, right_buttons, right_len);
85
86out:
87 layout[left_len + right_len] = '\0';
88}
89