summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Moreau <oreaus@gmail.com>2010-07-08 21:33:25 -0600
committerScott Moreau <oreaus@gmail.com>2010-07-08 21:33:25 -0600
commit5793c8910c68c9da561fbee296392cdf67f33076 (patch)
tree09fb3a426c2148ebbc4293abe2854653aa4dec9c /src
parentb8d9e270a83f1bc55f72b644f75bb4f74a159b8d (diff)
downloadtoggle-decoration-5793c8910c68c9da561fbee296392cdf67f33076.tar.gz
toggle-decoration-5793c8910c68c9da561fbee296392cdf67f33076.tar.bz2
Initial C++ commit.
Diffstat (limited to 'src')
-rw-r--r--src/toggledeco.cpp166
-rw-r--r--src/toggledeco.h98
2 files changed, 264 insertions, 0 deletions
diff --git a/src/toggledeco.cpp b/src/toggledeco.cpp
new file mode 100644
index 0000000..fff1833
--- /dev/null
+++ b/src/toggledeco.cpp
@@ -0,0 +1,166 @@
+/*
+ * Compiz Fusion Toggle-decoration plugin
+ *
+ * Copyright (c) 2008 Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Author(s):
+ * Eduardo Gurgel Pinho <edgurgel@gmail.com>
+ * Marco Diego Mesquita <marcodiegomesquita@gmail.com>
+ *
+ * Description:
+ *
+ * Toggles decorations of windows on/off.
+ *
+ */
+
+#include "toggledeco.h"
+
+/*
+ * Initially triggered keybinding.
+ * Fetch the window and toggles its decoration.
+ */
+
+bool
+ToggledecoScreen::trigger (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &option)
+{
+ CompWindow *cw = screen->findWindow (screen->activeWindow ());
+
+ if (cw)
+ {
+ TOGGLEDECO_WINDOW (cw);
+
+ MwmHints mwmhints;
+ Atom prop = Atoms::mwmHints;
+
+ memset(&mwmhints, 0, sizeof(mwmhints));
+
+ mwmhints.flags = MWM_HINTS_DECORATIONS;
+
+ if (tw->hasDecorations)
+ mwmhints.decorations = 0;
+ else
+ mwmhints.decorations = 1;
+
+ XChangeProperty(screen->dpy (), cw->id (), prop, prop, 32,
+ PropModeReplace, (unsigned char *) &mwmhints,
+ PROP_MWM_HINTS_ELEMENTS);
+
+ tw->hasDecorations = !tw->hasDecorations;
+ }
+
+ return true;
+}
+
+/*
+ * Testing if two windows are on the same viewport
+ */
+
+bool
+ToggledecoScreen::sameViewport (CompWindow* w1,
+ CompWindow* w2)
+{
+ CompPoint vp1, vp2;
+
+ vp1 = w1->defaultViewport ();
+ vp2 = w2->defaultViewport ();
+
+ return (vp1 == vp2);
+}
+
+/*
+ * Initially triggered keybinding.
+ * Fetch the every window and toggles its decoration.
+ */
+
+bool
+ToggledecoScreen::allTrigger (CompAction *action,
+ CompAction::State state,
+ CompOption::Vector &option)
+{
+ CompWindow *cw = screen->findWindow (screen->activeWindow ());
+
+ if (cw)
+ {
+ CompWindowList windows = screen->windows ();
+
+ foreach (CompWindow *w, windows)
+ {
+ TOGGLEDECO_WINDOW (w);
+
+ MwmHints mwmhints;
+ Atom prop = Atoms::mwmHints;
+
+ memset(&mwmhints, 0, sizeof(mwmhints));
+
+ mwmhints.flags = MWM_HINTS_DECORATIONS;
+
+ if (tw->hasDecorations)
+ mwmhints.decorations = 0;
+ else
+ mwmhints.decorations = 1;
+
+ if (!sameViewport (w, cw))
+ continue;
+
+ XChangeProperty(screen->dpy (), w->id (), prop, prop, 32,
+ PropModeReplace, (unsigned char *) &mwmhints,
+ PROP_MWM_HINTS_ELEMENTS);
+
+ tw->hasDecorations = !tw->hasDecorations;
+ }
+ }
+
+ return true;
+}
+
+ToggledecoScreen::ToggledecoScreen (CompScreen *screen) :
+ PluginClassHandler <ToggledecoScreen, CompScreen> (screen),
+ screen (screen),
+ cScreen (CompositeScreen::get (screen)),
+ gScreen (GLScreen::get (screen))
+{
+ ScreenInterface::setHandler (screen);
+ CompositeScreenInterface::setHandler (cScreen);
+ GLScreenInterface::setHandler (gScreen);
+
+ optionSetTriggerAllKeyInitiate (boost::bind (&ToggledecoScreen:: \
+ allTrigger, this, \
+ _1, _2, _3));
+ optionSetTriggerKeyInitiate (boost::bind (&ToggledecoScreen:: \
+ trigger, this, \
+ _1, _2, _3));
+}
+
+ToggledecoScreen::~ToggledecoScreen ()
+{
+}
+
+ToggledecoWindow::ToggledecoWindow (CompWindow *window) :
+ PluginClassHandler <ToggledecoWindow, CompWindow> (window),
+ window (window),
+ gScreen (ToggledecoScreen::get (screen)),
+ hasDecorations (true)
+{
+ WindowInterface::setHandler (window);
+}
+
+bool
+ToggledecoPluginVTable::init ()
+{
+ if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
+ return false;
+
+ return true;
+}
diff --git a/src/toggledeco.h b/src/toggledeco.h
new file mode 100644
index 0000000..96d6c13
--- /dev/null
+++ b/src/toggledeco.h
@@ -0,0 +1,98 @@
+/*
+ * Compiz Fusion Toggle-decoration plugin
+ *
+ * Copyright (c) 2008 Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Author(s):
+ * Eduardo Gurgel Pinho <edgurgel@gmail.com>
+ * Marco Diego Mesquita <marcodiegomesquita@gmail.com>
+ *
+ * Description:
+ *
+ * Toggles decorations of windows on/off.
+ *
+ */
+
+#include <core/core.h>
+#include <core/atoms.h>
+#include <core/pluginclasshandler.h>
+#include <composite/composite.h>
+#include <opengl/opengl.h>
+
+#include "toggledeco_options.h"
+
+#define MWM_HINTS_DECORATIONS (1L << 1);
+#define PROP_MWM_HINTS_ELEMENTS 5
+
+typedef struct {
+ unsigned long flags;
+ unsigned long functions;
+ unsigned long decorations;
+} MwmHints;
+
+class ToggledecoScreen :
+ public ScreenInterface,
+ public CompositeScreenInterface,
+ public GLScreenInterface,
+ public PluginClassHandler <ToggledecoScreen, CompScreen>,
+ public ToggledecoOptions
+{
+ public:
+
+ ToggledecoScreen (CompScreen *s);
+
+ ~ToggledecoScreen ();
+
+ CompScreen *screen;
+ CompositeScreen *cScreen;
+ GLScreen *gScreen;
+
+ bool
+ trigger (CompAction*,
+ CompAction::State,
+ CompOption::Vector&);
+
+ bool
+ sameViewport (CompWindow*, CompWindow*);
+
+ bool
+ allTrigger (CompAction*,
+ CompAction::State,
+ CompOption::Vector&);
+};
+
+class ToggledecoWindow :
+ public WindowInterface,
+ public PluginClassHandler <ToggledecoWindow, CompWindow>
+{
+ public:
+
+ ToggledecoWindow (CompWindow *);
+ CompWindow *window;
+ ToggledecoScreen *gScreen;
+
+ bool hasDecorations;
+};
+
+#define TOGGLEDECO_WINDOW(w) ToggledecoWindow *tw = ToggledecoWindow::get (w)
+
+class ToggledecoPluginVTable :
+ public CompPlugin::VTableForScreenAndWindow
+ <ToggledecoScreen, ToggledecoWindow>
+{
+ public:
+
+ bool init ();
+};
+
+COMPIZ_PLUGIN_20090315 (toggledeco, ToggledecoPluginVTable);