summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Xutil.cc79
-rw-r--r--src/Xutil.hh38
2 files changed, 117 insertions, 0 deletions
diff --git a/src/Xutil.cc b/src/Xutil.cc
new file mode 100644
index 0000000..5203469
--- /dev/null
+++ b/src/Xutil.cc
@@ -0,0 +1,79 @@
1// Xutil.cc for Fluxbox - an X11 Window manager
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net)
3// and Simon Bowden (rathnor at users.sourceforge.net)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22
23// $Id: Xutil.cc,v 1.1 2003/06/22 12:23:57 fluxgen Exp $
24
25#include "Xutil.hh"
26
27#include "I18n.hh"
28#include "App.hh"
29
30#include <X11/Xutil.h>
31#include <X11/Xatom.h>
32#include <X11/Xlib.h>
33
34namespace Xutil {
35
36std::string getWMName(Window window) {
37
38 if (window == None)
39 return "";
40
41 Display *display = FbTk::App::instance()->display();
42
43 XTextProperty text_prop;
44 char **list;
45 int num;
46 I18n *i18n = I18n::instance();
47 std::string name;
48
49 if (XGetWMName(display, window, &text_prop)) {
50 if (text_prop.value && text_prop.nitems > 0) {
51 if (text_prop.encoding != XA_STRING) {
52
53 text_prop.nitems = strlen((char *) text_prop.value);
54
55 if ((XmbTextPropertyToTextList(display, &text_prop,
56 &list, &num) == Success) &&
57 (num > 0) && *list) {
58 name = static_cast<char *>(*list);
59 XFreeStringList(list);
60 } else
61 name = text_prop.value ? (char *)text_prop.value : "";
62
63 } else
64 name = text_prop.value ? (char *)text_prop.value : "";
65 } else { // default name
66 name = i18n->getMessage(FBNLS::WindowSet, FBNLS::WindowUnnamed,
67 "Unnamed");
68 }
69 } else {
70 // default name
71 name = i18n->getMessage(FBNLS::WindowSet, FBNLS::WindowUnnamed,
72 "Unnamed");
73 }
74
75 return name;
76}
77
78}; // end namespace Xutil
79
diff --git a/src/Xutil.hh b/src/Xutil.hh
new file mode 100644
index 0000000..5cc7dfe
--- /dev/null
+++ b/src/Xutil.hh
@@ -0,0 +1,38 @@
1// Xutil.hh for Fluxbox - an X11 Window manager
2// Copyright (c) 2003 Henrik Kinnunen (fluxgen(at)users.sourceforge.net)
3// and Simon Bowden (rathnor at users.sourceforge.net)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a
6// copy of this software and associated documentation files (the "Software"),
7// to deal in the Software without restriction, including without limitation
8// the rights to use, copy, modify, merge, publish, distribute, sublicense,
9// and/or sell copies of the Software, and to permit persons to whom the
10// Software is furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21// DEALINGS IN THE SOFTWARE.
22
23// $Id: Xutil.hh,v 1.1 2003/06/22 12:23:57 fluxgen Exp $
24
25#ifndef XUTIL_HH
26#define XUTIL_HH
27
28#include <X11/Xlib.h>
29
30#include <string>
31
32namespace Xutil {
33
34std::string getWMName(Window window);
35
36}; // end namespace Xutil
37
38#endif // XUTIL_HH