[Xfce4-commits] <xfce4-wmdock-plugin:master> Added the newest developer branch with the new panel off mode.
Andre Ellguth
noreply at xfce.org
Mon Nov 4 13:36:01 CET 2013
Updating branch refs/heads/master
to 28cb3b0aa6d8ac01d1fdcf5e457861cc1277050b (commit)
from 97ef602ea22226d3e449837626ac169ee905f5d1 (commit)
commit 28cb3b0aa6d8ac01d1fdcf5e457861cc1277050b
Author: Andre Ellguth <andre at ellguth.com>
Date: Wed Aug 15 11:38:37 2012 +0200
Added the newest developer branch with the new panel off mode.
panel-plugin/catchwindow.c | 259 ++++++
panel-plugin/{wmdock.h => catchwindow.h} | 41 +-
panel-plugin/debug.c | 76 ++
panel-plugin/{wmdock.h => debug.h} | 44 +-
panel-plugin/dnd.c | 183 ++++
panel-plugin/{wmdock.h => dnd.h} | 48 +-
panel-plugin/dockapp.c | 738 +++++++++++++++
panel-plugin/dockapp.h | 76 ++
panel-plugin/{wmdock.h => extern.h} | 49 +-
panel-plugin/misc.c | 181 ++++
panel-plugin/{wmdock.h => misc.h} | 53 +-
panel-plugin/props.c | 514 +++++++++++
panel-plugin/{wmdock.h => props.h} | 46 +-
panel-plugin/rcfile.c | 159 ++++
panel-plugin/{wmdock.h => rcfile.h} | 44 +-
panel-plugin/wmdock.c | 1436 ++----------------------------
panel-plugin/wmdock.h | 43 +-
17 files changed, 2376 insertions(+), 1614 deletions(-)
diff --git a/panel-plugin/catchwindow.c b/panel-plugin/catchwindow.c
new file mode 100644
index 0000000..2fae482
--- /dev/null
+++ b/panel-plugin/catchwindow.c
@@ -0,0 +1,259 @@
+/* wmdock xfce4 plugin by Andre Ellguth
+ * Catch the window if is a dockapp.
+ *
+ * $Id: catchwindow.c 26 2012-08-11 21:04:14Z ellguth $
+ *
+ * Authors:
+ * Andre Ellguth <ellguth at ibh.de>
+ *
+ * License:
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this package; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+
+#define WNCK_I_KNOW_THIS_IS_UNSTABLE
+#include <libwnck/libwnck.h>
+
+#include <gtk/gtk.h>
+#include <libxfce4util/libxfce4util.h>
+#include <libxfcegui4/libxfcegui4.h>
+#include <libxfce4panel/libxfce4panel.h>
+
+#include "extern.h"
+#include "catchwindow.h"
+#include "wmdock.h"
+#include "debug.h"
+#include "dockapp.h"
+#include "misc.h"
+#include "props.h"
+
+
+static gchar *wmdock_get_dockapp_cmd(WnckWindow *w)
+{
+ gchar *cmd = NULL;
+ int wpid = 0;
+ int argc = 0;
+ int fcnt, i;
+ char **argv;
+ FILE *procfp = NULL;
+ char buf[BUF_MAX];
+
+ XGetCommand(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
+ wnck_window_get_xid(w), &argv, &argc);
+ if(argc > 0) {
+ argv = (char **) realloc(argv, sizeof(char *) * (argc + 1));
+ argv[argc] = NULL;
+ cmd = g_strjoinv (" ", argv);
+ XFreeStringList(argv);
+ } else {
+ /* Try to get the command line from the proc fs. */
+ wpid = wnck_window_get_pid (w);
+
+ if(wpid) {
+ sprintf(buf, "/proc/%d/cmdline", wpid);
+
+ procfp = fopen(buf, "r");
+
+ if(procfp) {
+ fcnt = read(fileno(procfp), buf, BUF_MAX);
+
+ cmd = g_malloc(fcnt+2);
+ if(!cmd) return (NULL);
+
+ for(i = 0; i < fcnt; i++) {
+ if(buf[i] == 0)
+ *(cmd+i) = ' ';
+ else
+ *(cmd+i) = buf[i];
+ }
+ *(cmd+(i-1)) = 0;
+
+ fclose(procfp);
+ }
+ }
+ }
+
+ if(!cmd) {
+ /* If nothing helps fallback to the window name. */
+ cmd = g_strdup(wnck_window_get_name(w));
+ }
+
+ return(cmd);
+}
+
+
+void wmdock_window_open(WnckScreen *s, WnckWindow *w)
+{
+ int wi, he;
+ XWMHints *h = NULL;
+ XWindowAttributes attr;
+ DockappNode *dapp = NULL;
+ GList *_dapps = NULL;
+ gchar *cmd = NULL;
+ gboolean rcDapp = FALSE;
+
+ gdk_error_trap_push();
+ gdk_flush();
+
+ h = XGetWMHints(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
+ wnck_window_get_xid(w));
+
+ if(!h) return;
+
+ if(h->initial_state == WithdrawnState ||
+ h->flags == (WindowGroupHint | StateHint | IconWindowHint)
+ || has_dockapp_hint(w)) {
+
+ debug("catchwindow.c: new wmapp open");
+ debug("catchwindow.c: New dockapp %s with xid:%u pid:%u arrived sessid:%s",
+ wnck_window_get_name(w), wnck_window_get_xid(w),
+ wnck_window_get_pid(w), wnck_window_get_session_id(w));
+
+ cmd = wmdock_get_dockapp_cmd(w);
+
+ if(wmdock->propDispAddOnlyWM == TRUE &&
+ comp_dockapp_with_filterlist(wnck_window_get_name(w)) == FALSE &&
+ ! (wmdock_find_startup_dockapp(cmd))) {
+ XFree(h);
+ return;
+ }
+
+ if(!cmd) {
+ XFree(h);
+ return;
+ }
+ debug("catchwindow.c: found cmd %s for window %s", cmd, wnck_window_get_name(w));
+
+ if(rcCmds && (dapp = wmdock_find_startup_dockapp(cmd)))
+ rcDapp = TRUE;
+
+ if(rcDapp == FALSE) {
+ debug("catchwindow.c: Create a new dapp window %s", wnck_window_get_name(w));
+
+ dapp = g_new0(DockappNode, 1);
+ dapp->s = GTK_SOCKET(gtk_socket_new());
+ }
+
+ if(h->initial_state == WithdrawnState && h->icon_window) {
+ XUnmapWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
+ wnck_window_get_xid(w));
+ dapp->i =h->icon_window;
+ } else {
+ dapp->i = wnck_window_get_xid(w);
+ }
+
+ if(!XGetWindowAttributes(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
+ dapp->i, &attr)) {
+ wi = DEFAULT_DOCKAPP_WIDTH;
+ he = DEFAULT_DOCKAPP_HEIGHT;
+ } else {
+ wi = attr.width;
+ he = attr.height;
+ }
+
+ if(wi > DEFAULT_DOCKAPP_WIDTH || he > DEFAULT_DOCKAPP_HEIGHT) {
+ /* It seems to be no dockapp, because the width or the height of the
+ * window a greater than 64 pixels. */
+ XMapWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
+ wnck_window_get_xid(w));
+ gtk_widget_destroy(GTK_WIDGET(dapp->s));
+ g_free(cmd);
+ g_free(dapp);
+ XFree(h);
+ return;
+ }
+
+ debug("catchwindow.c: New dockapp %s width: %d height: %d", wnck_window_get_name(w), wi, he);
+
+ gtk_widget_set_size_request(GTK_WIDGET(dapp->s), wi, he);
+ wnck_window_set_skip_tasklist (w, TRUE);
+ wnck_window_set_skip_pager (w, TRUE);
+
+ /* Set this property to skip the XFCE4 session manager. */
+ set_xsmp_support(w);
+
+ dapp->name = g_strdup(wnck_window_get_name(w));
+ dapp->cmd = cmd;
+
+ if(wmdockIcon && !IS_PANELOFF(wmdock)) {
+ gtk_widget_destroy(wmdockIcon);
+ wmdockIcon = NULL;
+ }
+
+ /* Cleanly unmap the original window. */
+ XUnmapWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), dapp->i);
+
+ if(rcDapp == FALSE) {
+ dapp->tile = wmdock_create_tile_from_socket(dapp);
+ /* Setup tile background. */
+ wmdock_set_tile_background(dapp, gdkPbTileDefault);
+
+ if( ! IS_PANELOFF(wmdock) ) {
+ /* Setup the DockApp in the XFCE-panel. */
+ gtk_box_pack_start(GTK_BOX(wmdock->box), dapp->tile, FALSE, FALSE, 0);
+ } else {
+ /* Setup the DockApp for the WindowMaker like style. */
+ gtk_widget_show_all(GTK_WIDGET(dapp->tile));
+ wmdock_set_autoposition_dockapp(dapp,
+ g_list_last(wmdock->dapps) ? g_list_last(wmdock->dapps)->data : NULL);
+ }
+ }
+
+ gtk_socket_add_id(dapp->s, dapp->i);
+
+ gtk_widget_show_all(GTK_WIDGET(dapp->tile));
+
+ g_signal_connect(dapp->s, "plug-removed", G_CALLBACK(wmdock_dapp_closed), dapp);
+
+ if(rcDapp == FALSE)
+ wmdock->dapps=g_list_append(wmdock->dapps, dapp);
+
+ /* Setup drag & drop for the dockapps. */
+ g_list_foreach(wmdock->dapps, (GFunc) wmdock_setupdnd_dockapp, NULL);
+
+ /* Bring all dockapps to the front if a new one shown (panel off mode). */
+ g_list_foreach(wmdock->dapps, (GFunc) wmdock_dockapp_tofront, NULL);
+
+ if( IS_PANELOFF(wmdock) ) {
+ if(rcDapp == TRUE) {
+ _dapps = g_list_find(wmdock->dapps, (gconstpointer) dapp);
+ wmdock_set_autoposition_dockapp( dapp,
+ (DOCKAPP(g_list_first(wmdock->dapps)->data) != dapp && _dapps) ?
+ DOCKAPP(g_list_previous(_dapps)->data) : NULL);
+
+ /* Workaround to display the tile background. */
+ if(wmdock->propDispTile == TRUE)
+ wmdock_redraw_dockapp(dapp);
+ }
+
+ /* Setup the event handler for the window. */
+ g_signal_connect(dapp->tile, "event-after", G_CALLBACK(wmdock_dockapp_paneloff_handler),
+ dapp);
+ }
+ /* Clear the noisy background. */
+ wmdock_redraw_dockapp(dapp);
+
+ wmdock_refresh_properties_dialog();
+ }
+
+ XFree(h);
+}
diff --git a/panel-plugin/wmdock.h b/panel-plugin/catchwindow.h
similarity index 53%
copy from panel-plugin/wmdock.h
copy to panel-plugin/catchwindow.h
index f8c42c9..e7918c5 100644
--- a/panel-plugin/wmdock.h
+++ b/panel-plugin/catchwindow.h
@@ -1,6 +1,7 @@
/* wmdock xfce4 plugin by Andre Ellguth
+ * catchwindow.h
*
- * $Id$
+ * $Id: catchwindow.h 11 2012-05-29 19:45:56Z ellguth $
*
* Authors:
* Andre Ellguth <ellguth at ibh.de>
@@ -21,40 +22,12 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __WMDOCK_H__
-#define __WMDOCK_H__
+#ifndef __CATCHWINDOW_H__
+#define __CATCHWINDOW_H__
-#include <gtk/gtk.h>
-#include <libxfce4panel/libxfce4panel.h>
+/* Prototypes */
+void wmdock_window_open(WnckScreen *, WnckWindow *);
-#define WNCK_I_KNOW_THIS_IS_UNSTABLE
-#include <libwnck/libwnck.h>
-typedef struct _dockapp {
- GtkSocket *s;
- GdkNativeWindow i;
- GtkWidget *bg;
- GtkWidget *tile;
- gchar *name;
- gchar *cmd;
-} DockappNode;
-typedef struct {
- XfcePanelPlugin *plugin;
-
- GtkWidget *eventBox;
-
- /* Plugin specific definitions */
- GtkWidget *align;
- GtkWidget *box;
- GtkWidget *panelBox;
-
- gboolean propDispTile;
- gboolean propDispPropButton;
- gboolean propDispAddOnlyWM;
- gchar *filterList;
-
- GList *dapps;
-} WmdockPlugin;
-
-#endif /* __WMDOCK_H__ */
+#endif /* __CATCHWINDOW_H__ */
diff --git a/panel-plugin/debug.c b/panel-plugin/debug.c
new file mode 100644
index 0000000..7115910
--- /dev/null
+++ b/panel-plugin/debug.c
@@ -0,0 +1,76 @@
+/* wmdock xfce4 plugin by Andre Ellguth
+ * Debug output.
+ *
+ * $Id: debug.c 10 2012-05-29 06:29:21Z ellguth $
+ *
+ * Authors:
+ * Andre Ellguth <ellguth at ibh.de>
+ *
+ * License:
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this package; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include "debug.h"
+#include "wmdock.h"
+
+#if DEBUG
+static FILE *fp = (FILE *) NULL;
+#endif
+
+void init_debug()
+{
+#if DEBUG
+ char debugFile[BUF_MAX];
+
+ sprintf(debugFile, "%s/wmdock-debug.%d", g_get_tmp_dir(), getpid());
+ fp = fopen(debugFile, "w");
+ if(!fp) fp = stderr;
+
+ debug("debug.c: Debug initialized.");
+#endif
+}
+
+
+void debug(const char *format, ...)
+{
+#if DEBUG
+ char buf[BUF_MAX];
+ va_list args;
+ time_t curtime;
+ struct tm *loctime;
+
+ if(!fp) {
+ return;
+ }
+
+ va_start(args, format);
+ curtime = time (NULL);
+ loctime = localtime (&curtime);
+ strftime(buf, BUF_MAX, "%B %d %I:%M:%S", loctime);
+
+ fprintf(fp, "%s: ", buf);
+ vfprintf(fp, format, args);
+ fprintf(fp, "\n");
+ fflush(fp);
+
+ va_end(args);
+#endif /* DEBUG */
+}
+
+
diff --git a/panel-plugin/wmdock.h b/panel-plugin/debug.h
similarity index 53%
copy from panel-plugin/wmdock.h
copy to panel-plugin/debug.h
index f8c42c9..2a014e7 100644
--- a/panel-plugin/wmdock.h
+++ b/panel-plugin/debug.h
@@ -1,6 +1,7 @@
/* wmdock xfce4 plugin by Andre Ellguth
+ * debug.h
*
- * $Id$
+ * $Id: debug.h 5 2012-05-23 18:16:58Z ellguth $
*
* Authors:
* Andre Ellguth <ellguth at ibh.de>
@@ -21,40 +22,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __WMDOCK_H__
-#define __WMDOCK_H__
+#ifndef __DEBUG_H__
+#define __DEBUG_H__
-#include <gtk/gtk.h>
-#include <libxfce4panel/libxfce4panel.h>
+/* Prototypes */
+void init_debug();
+void debug(const char *, ...);
-#define WNCK_I_KNOW_THIS_IS_UNSTABLE
-#include <libwnck/libwnck.h>
-
-typedef struct _dockapp {
- GtkSocket *s;
- GdkNativeWindow i;
- GtkWidget *bg;
- GtkWidget *tile;
- gchar *name;
- gchar *cmd;
-} DockappNode;
-
-typedef struct {
- XfcePanelPlugin *plugin;
-
- GtkWidget *eventBox;
-
- /* Plugin specific definitions */
- GtkWidget *align;
- GtkWidget *box;
- GtkWidget *panelBox;
-
- gboolean propDispTile;
- gboolean propDispPropButton;
- gboolean propDispAddOnlyWM;
- gchar *filterList;
-
- GList *dapps;
-} WmdockPlugin;
-
-#endif /* __WMDOCK_H__ */
+#endif /* __DEBUG_H__ */
diff --git a/panel-plugin/dnd.c b/panel-plugin/dnd.c
new file mode 100644
index 0000000..852a91b
--- /dev/null
+++ b/panel-plugin/dnd.c
@@ -0,0 +1,183 @@
+/* wmdock xfce4 plugin by Andre Ellguth
+ * Drag & Drop functions.
+ *
+ * $Id: dnd.c 23 2012-08-09 19:39:15Z ellguth $
+ *
+ * Authors:
+ * Andre Ellguth <ellguth at ibh.de>
+ *
+ * License:
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this package; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+
+#define WNCK_I_KNOW_THIS_IS_UNSTABLE
+#include <libwnck/libwnck.h>
+
+#include <gtk/gtk.h>
+#include <libxfce4util/libxfce4util.h>
+
+#include "extern.h"
+#include "wmdock.h"
+#include "debug.h"
+#include "dockapp.h"
+#include "misc.h"
+#include "dnd.h"
+
+#include "xfce4-wmdock-plugin.xpm"
+
+#define _BYTE 8
+
+void drag_begin_handl (GtkWidget *widget, GdkDragContext *context,
+ gpointer dapp)
+{
+ gdkPbIcon = get_icon_from_xpm_scaled((const char **) xfce4_wmdock_plugin_xpm,
+ DEFAULT_DOCKAPP_WIDTH/2,
+ DEFAULT_DOCKAPP_HEIGHT/2);
+
+ gtk_drag_set_icon_pixbuf (context, gdkPbIcon, 0, 0);
+
+ g_object_unref (G_OBJECT(gdkPbIcon));
+}
+
+#if (GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 12)
+gboolean drag_failed_handl(GtkWidget *widget, GdkDragContext *context,
+ GtkDragResult result, gpointer dapp)
+{
+ GtkWidget *gtkDlg;
+
+ if(result == GTK_DRAG_RESULT_NO_TARGET && dapp) {
+ gtkDlg = gtk_message_dialog_new(GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (wmdock->plugin))),
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_YES_NO,
+ _("Do you want remove the dockapp \"%s\"?"),
+ ((DockappNode *) dapp)->name);
+
+ if(gtk_dialog_run (GTK_DIALOG(gtkDlg)) == GTK_RESPONSE_YES)
+ wmdock_destroy_dockapp((DockappNode *) dapp);
+
+ gtk_widget_destroy (GTK_WIDGET(gtkDlg));
+ }
+ debug("dnd.c: Drag failed of dockapp %s", ((DockappNode *) dapp)->name);
+
+ return TRUE;
+}
+#endif
+
+
+gboolean drag_drop_handl (GtkWidget *widget, GdkDragContext *context,
+ gint x, gint y, guint time, gpointer dapp)
+{
+ gboolean is_valid_drop_site;
+ GdkAtom target_type;
+
+ is_valid_drop_site = TRUE;
+
+ if (context-> targets)
+ {
+ target_type = GDK_POINTER_TO_ATOM
+ (g_list_nth_data (context-> targets, 0));
+
+ gtk_drag_get_data (widget,context, target_type, time);
+ }
+
+ else
+ {
+ is_valid_drop_site = FALSE;
+ }
+
+ return is_valid_drop_site;
+}
+
+
+
+void drag_data_received_handl (GtkWidget *widget,
+ GdkDragContext *context, gint x, gint y,
+ GtkSelectionData *selection_data,
+ guint target_type, guint time,
+ gpointer dapp)
+{
+ glong *_idata;
+ gboolean dnd_success = FALSE;
+ GList *dappsSrc = NULL;
+ GList *dappsDst = NULL;
+
+ if(target_type == 0) {
+ _idata = (glong*) selection_data-> data;
+ debug("dnd.c: DnD integer received: %ld", *_idata);
+
+ dnd_success = TRUE;
+
+ if(dapp) {
+ dappsSrc = g_list_nth(wmdock->dapps, *_idata);
+ dappsDst = g_list_find(wmdock->dapps, (DockappNode *) dapp);
+
+ if(dappsSrc->data != dappsDst->data) {
+ debug("dnd.c: DnD src dockapp name: %s",
+ DOCKAPP(dappsSrc->data)->name);
+ debug("dnd.c: DnD dst dockapp name: %s",
+ DOCKAPP(dapp)->name);
+
+ dappsDst->data = dappsSrc->data;
+ dappsSrc->data = dapp;
+
+ debug("dnd.c: DnD src index: %d",
+ g_list_index (wmdock->dapps, dappsSrc->data));
+ debug("dnd.c: DnD dst index: %d",
+ g_list_index (wmdock->dapps, dappsDst->data));
+
+ gtk_box_reorder_child(GTK_BOX(wmdock->box),
+ GTK_WIDGET(DOCKAPP(dappsSrc->data)->tile),
+ g_list_index (wmdock->dapps, dappsSrc->data));
+ gtk_box_reorder_child(GTK_BOX(wmdock->box),
+ GTK_WIDGET(DOCKAPP(dappsDst->data)->tile),
+ g_list_index (wmdock->dapps, dappsDst->data));
+
+ g_list_foreach(wmdock->dapps, (GFunc)wmdock_redraw_dockapp, NULL);
+ }
+ }
+
+ }
+
+ gtk_drag_finish (context, dnd_success, FALSE, time);
+
+}
+
+
+
+void drag_data_get_handl (GtkWidget *widget, GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint target_type, guint time,
+ gpointer dapp)
+{
+ gint index;
+
+ if(target_type == 0 && dapp) {
+ index = g_list_index (wmdock->dapps, (DockappNode *) dapp);
+
+ gtk_selection_data_set (selection_data, selection_data->target,
+ sizeof(index) * _BYTE,
+ (guchar*) &index, sizeof (index));
+
+ debug("dnd.c: DnD Integer sent: %ld", index);
+ }
+}
diff --git a/panel-plugin/wmdock.h b/panel-plugin/dnd.h
similarity index 53%
copy from panel-plugin/wmdock.h
copy to panel-plugin/dnd.h
index f8c42c9..648e3d4 100644
--- a/panel-plugin/wmdock.h
+++ b/panel-plugin/dnd.h
@@ -1,6 +1,7 @@
/* wmdock xfce4 plugin by Andre Ellguth
+ * dnd.h
*
- * $Id$
+ * $Id: dnd.h 4 2012-05-23 12:45:49Z ellguth $
*
* Authors:
* Andre Ellguth <ellguth at ibh.de>
@@ -21,40 +22,15 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __WMDOCK_H__
-#define __WMDOCK_H__
+#ifndef __DND_H__
+#define __DND_H__
-#include <gtk/gtk.h>
-#include <libxfce4panel/libxfce4panel.h>
+void drag_begin_handl (GtkWidget *, GdkDragContext *, gpointer);
+gboolean drag_drop_handl (GtkWidget *, GdkDragContext *, gint, gint, guint, gpointer);
+void drag_data_received_handl (GtkWidget *, GdkDragContext *, gint, gint, GtkSelectionData *, guint, guint, gpointer);
+void drag_data_get_handl (GtkWidget *, GdkDragContext *, GtkSelectionData *, guint, guint, gpointer);
+#if (GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 12)
+gboolean drag_failed_handl(GtkWidget *, GdkDragContext *, GtkDragResult, gpointer);
+#endif
-#define WNCK_I_KNOW_THIS_IS_UNSTABLE
-#include <libwnck/libwnck.h>
-
-typedef struct _dockapp {
- GtkSocket *s;
- GdkNativeWindow i;
- GtkWidget *bg;
- GtkWidget *tile;
- gchar *name;
- gchar *cmd;
-} DockappNode;
-
-typedef struct {
- XfcePanelPlugin *plugin;
-
- GtkWidget *eventBox;
-
- /* Plugin specific definitions */
- GtkWidget *align;
- GtkWidget *box;
- GtkWidget *panelBox;
-
- gboolean propDispTile;
- gboolean propDispPropButton;
- gboolean propDispAddOnlyWM;
- gchar *filterList;
-
- GList *dapps;
-} WmdockPlugin;
-
-#endif /* __WMDOCK_H__ */
+#endif /* __DND_H__ */
diff --git a/panel-plugin/dockapp.c b/panel-plugin/dockapp.c
new file mode 100644
index 0000000..86895ce
--- /dev/null
+++ b/panel-plugin/dockapp.c
@@ -0,0 +1,738 @@
+/* wmdock xfce4 plugin by Andre Ellguth
+ * Dockapp handling.
+ *
+ * $Id: dockapp.c 28 2012-08-12 12:31:28Z ellguth $
+ *
+ * Authors:
+ * Andre Ellguth <ellguth at ibh.de>
+ *
+ * License:
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this package; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+
+#define WNCK_I_KNOW_THIS_IS_UNSTABLE
+#include <libwnck/libwnck.h>
+
+#include <gtk/gtk.h>
+#include <libxfce4util/libxfce4util.h>
+#include <libxfcegui4/libxfcegui4.h>
+#include <libxfce4panel/libxfce4panel.h>
+
+#include "extern.h"
+#include "dockapp.h"
+#include "wmdock.h"
+#include "debug.h"
+#include "dnd.h"
+#include "misc.h"
+#include "props.h"
+
+#define DEFAULT_XPANEL_NAME "xfce4-panel"
+
+static GtkTargetEntry targetList[] = {
+ { "INTEGER", 0, 0 }
+};
+static guint nTargets = G_N_ELEMENTS (targetList);
+static DockappNode *dummy = NULL;
+
+
+/**
+ * Get the x coordinate child dockapp.
+ *
+ * @param dapp Parent dockapp.
+ * @param prevDapp Child dockapp.
+ * @param gluepos Orientation of the child dockapp.
+ * @param x Pointer to x.
+ * @param y Pointer to y.
+ */
+static void wmdock_dockapp_child_pos(DockappNode *prevDapp, gint gluepos, gint *x, gint *y)
+{
+ gint prevx, prevy;
+
+ /* Setup the position of the first dockapp. */
+ prevx = prevy = 0;
+
+ /* Get the position of the previous DockApp if is accessable. */
+ gtk_window_get_position(
+ GTK_WINDOW (GTK_WIDGET (prevDapp->tile)),
+ &prevx, &prevy);
+
+ switch(gluepos) {
+ case GLUE_T:
+ *x = prevx;
+ *y = prevy - DEFAULT_DOCKAPP_HEIGHT;
+ break;
+ case GLUE_TL:
+ *x = prevx - DEFAULT_DOCKAPP_WIDTH;
+ *y = prevy - DEFAULT_DOCKAPP_HEIGHT;
+ break;
+ case GLUE_TR:
+ *x = prevx + DEFAULT_DOCKAPP_WIDTH;
+ *y = prevy - DEFAULT_DOCKAPP_HEIGHT;
+ break;
+ case GLUE_B:
+ *x = prevx;
+ *y = prevy + DEFAULT_DOCKAPP_HEIGHT;
+ break;
+ case GLUE_BL:
+ *x = prevx - DEFAULT_DOCKAPP_WIDTH;
+ *y = prevy + DEFAULT_DOCKAPP_HEIGHT;
+ break;
+ case GLUE_BR:
+ *x = prevx + DEFAULT_DOCKAPP_WIDTH;
+ *y = prevy + DEFAULT_DOCKAPP_HEIGHT;
+ break;
+ case GLUE_L:
+ *x = prevx - DEFAULT_DOCKAPP_WIDTH;
+ *y = prevy;
+ break;
+ case GLUE_R:
+ *x = prevx + DEFAULT_DOCKAPP_WIDTH;
+ *y = prevy;
+ break;
+ default:
+ break;
+ }
+}
+
+
+/**
+ * Insert a dummy and move dockapp and replace the other dockapps.
+ *
+ * @param dapp Position for dummy placement.
+ */
+static void wmdock_insert_dummy(DockappNode *dapp)
+{
+ gint i, x, y;
+
+ if(!dummy) {
+ dummy = g_new0(DockappNode, 1);
+ dummy->name = g_strdup("dummy");
+ dummy->tile = wmdock_create_dummy();
+ }
+
+ for(i = 0; i < GLUE_MAX; i++)
+ dummy->glue[i] = dapp->glue[i];
+
+ gtk_widget_show(dummy->tile);
+
+ gtk_window_get_position(GTK_WINDOW(dapp->tile), &x, &y);
+ debug("dockapp.c: Move dummy dockapp to x: %d, y: %d", x, y);
+ gtk_window_move(GTK_WINDOW(dummy->tile), x, y);
+
+ wmdock_order_dockapps(dummy);
+}
+
+
+static void wmdock_destroy_dummy()
+{
+ if(!dummy)
+ return;
+
+ gtk_widget_destroy(dummy->tile);
+ g_free(dummy->name);
+ g_free(dummy);
+
+ dummy = NULL;
+
+ wmdock_order_dockapps(DOCKAPP(g_list_first(wmdock->dapps)->data));
+}
+
+
+/**
+ * Event handler for the tile in panel off mode.
+ *
+ * @param tile The window of the event.
+ * @param ev Event informations.
+ * @param dapp DockappNode of the event.
+ */
+void wmdock_dockapp_paneloff_handler(GtkWidget *tile, GdkEvent *ev, DockappNode *dapp)
+{
+ static DockappNode *dappOnMove = NULL;
+
+ debug("dockapp.c: Window event: %d. (dapp: %s), dappOnMove: %s", ev->type, dapp->name,
+ dappOnMove ? "Yes": "No");
+
+ switch(ev->type) {
+ case GDK_CONFIGURE: /* Movement. */
+ if(dappOnMove)
+ break;
+ break;
+ case GDK_BUTTON_PRESS:
+ case GDK_KEY_PRESS:
+ dappOnMove = dapp;
+
+ break;
+ case GDK_BUTTON_RELEASE:
+ case GDK_KEY_RELEASE:
+ debug("dockapp.c: Window event button release on %s.", dapp->name);
+ wmdock_set_autoposition_dockapp(dapp, wmdock_get_parent_dockapp(dapp));
+ dappOnMove = NULL;
+ wmdock_destroy_dummy();
+ break;
+ case GDK_FOCUS_CHANGE:
+ if(ev->focus_change.in == TRUE) {
+ /* `in' is true if window window got the focus. */
+ g_list_foreach(wmdock->dapps, (GFunc) wmdock_dockapp_tofront, NULL);
+ }
+
+ break;
+ case GDK_VISIBILITY_NOTIFY:
+ if(dappOnMove) {
+ if(dapp == dappOnMove)
+ break;
+
+ if(ev->visibility.state == GDK_VISIBILITY_PARTIAL ||
+ ev->visibility.state == GDK_VISIBILITY_FULLY_OBSCURED) {
+ // wmdock_insert_dummy(dapp);
+ }
+ } else {
+ wmdock_redraw_dockapp(dapp);
+ wmdock_destroy_dummy();
+ }
+ break;
+ default:
+ break;
+ }
+}
+
+
+/**
+ * Set focus to a dockapp.
+ *
+ * @param dapp DockappNode to focus.
+ */
+void wmdock_dockapp_tofront(DockappNode *dapp) {
+ if(!dapp)
+ return;
+
+ if ( IS_PANELOFF(wmdock) )
+ gdk_window_raise(dapp->tile->window);
+}
+
+
+gboolean wmdock_startup_dockapp(const gchar *cmd)
+{
+ gboolean ret;
+ GError *err = NULL;
+
+ ret = xfce_exec(cmd, FALSE, FALSE, &err);
+
+ /* Errors will be evaluate in a later version. */
+ if(err) g_clear_error (&err);
+
+ return(ret);
+}
+
+
+void wmdock_destroy_dockapp(DockappNode *dapp)
+{
+ debug("dockapp.c: Destroy dockapp %s", dapp->name);
+ XDestroyWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), dapp->i);
+}
+
+
+void wmdock_setupdnd_dockapp(DockappNode *dapp)
+{
+ if( ! IS_PANELOFF(wmdock)) {
+ /* Make the "well label" a DnD destination. */
+ gtk_drag_dest_set (GTK_WIDGET(dapp->s), GTK_DEST_DEFAULT_MOTION, targetList,
+ nTargets, GDK_ACTION_MOVE);
+
+ gtk_drag_source_set (GTK_WIDGET(dapp->s), GDK_BUTTON1_MASK, targetList,
+ nTargets, GDK_ACTION_MOVE);
+
+ g_signal_connect (dapp->s, "drag-begin",
+ G_CALLBACK (drag_begin_handl), dapp);
+
+ g_signal_connect (dapp->s, "drag-data-get",
+ G_CALLBACK (drag_data_get_handl), dapp);
+
+#if (GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 12)
+ g_signal_connect (dapp->s, "drag-failed",
+ G_CALLBACK (drag_failed_handl), dapp);
+#endif
+
+ g_signal_connect (dapp->s, "drag-data-received",
+ G_CALLBACK(drag_data_received_handl), dapp);
+ g_signal_connect (dapp->s, "drag-drop",
+ G_CALLBACK (drag_drop_handl), dapp);
+
+ debug("dockapp.c: Setup DnD for dockapp %s", dapp->name);
+ }
+}
+
+
+DockappNode *wmdock_find_startup_dockapp(const gchar *compCmd)
+{
+ GList *dapps;
+ DockappNode *dapp = NULL;
+
+ dapps = wmdock->dapps;
+
+ while(dapps) {
+ dapp = DOCKAPP(dapps->data);
+
+ if(dapp) {
+ if(!dapp->name && dapp->cmd) {
+ if(!g_ascii_strcasecmp(dapp->cmd, compCmd)) {
+ debug("dockapp.c: found startup dockapp with cmd %s", compCmd);
+ return(dapp);
+ }
+ }
+ }
+
+ dapps = g_list_next(dapps);
+ }
+
+ return(NULL);
+}
+
+/**
+ * Removes the anchor from dockapp.
+ *
+ * @param anchor The anchor dockapp.
+ * @param dapp Dockapp to unlink.
+ */
+void wmdock_remove_anchor_dockapp(DockappNode *anchor, DockappNode *dapp)
+{
+ gint i;
+
+ if( ! IS_PANELOFF(wmdock) || !anchor || !dapp)
+ return;
+
+ for(i = 0; i < GLUE_MAX; i++) {
+ if(anchor->glue[i] == dapp) {
+ debug("Remove glue from parent: %s", anchor->name);
+ anchor->glue[i] = NULL;
+ }
+ }
+}
+
+
+/**
+ * Clear data of a DockappNode and reorder the other.
+ *
+ * @param dapp DockappNode to free.
+ */
+void wmdock_free_dockapp(DockappNode *dapp)
+{
+ gint i;
+ DockappNode *_dapp = NULL;
+
+ if( IS_PANELOFF(wmdock) ) {
+ _dapp = wmdock_get_parent_dockapp(dapp);
+ if(_dapp) {
+ /* Remove the glue of dapp from the parent. */
+ wmdock_remove_anchor_dockapp(_dapp, dapp);
+
+ /* Cover all the glue from the closed dockapp to the parent. */
+ for(i = 0; i < GLUE_MAX; i++) {
+ if(dapp->glue[i]) {
+ if(!_dapp->glue[i]) {
+ _dapp->glue[i] = dapp->glue[i];
+ } else {
+ // TODO: Verify this code, maybe broken?
+
+ /* If another glue is on the parent destroy the others. */
+ wmdock_destroy_dockapp(dapp->glue[i]);
+ wmdock_free_dockapp(dapp->glue[i]);
+ }
+ }
+ }
+ }
+ }
+
+ wmdock->dapps = g_list_remove_all(wmdock->dapps, dapp);
+ gtk_widget_destroy(GTK_WIDGET(dapp->tile));
+ g_free(dapp->name);
+ g_free(dapp->cmd);
+ g_free(dapp);
+
+ if(g_list_length (wmdock->dapps) == 0) {
+ wmdock_panel_draw_wmdock_icon(FALSE);
+ }
+
+ if( IS_PANELOFF(wmdock) && g_list_first(wmdock->dapps))
+ wmdock_order_dockapps(DOCKAPP(g_list_first(wmdock->dapps)->data));
+
+ wmdock_refresh_properties_dialog();
+}
+
+
+void wmdock_dapp_closed(GtkSocket *socket, DockappNode *dapp)
+{
+ debug("dockapp.c: closed window signal ! (dockapp: %s)", dapp->name);
+ wmdock_free_dockapp(dapp);
+}
+
+
+void wmdock_redraw_dockapp(DockappNode *dapp)
+{
+ gtk_widget_unmap (GTK_WIDGET(dapp->s));
+ wmdock_set_tile_background(dapp, gdkPbTileDefault);
+
+ debug("dockapp.c: Dockapp %s redrawed with tile %d", dapp->name, wmdock->propDispTile);
+
+ if(dapp->bg)
+ gdk_window_process_updates(dapp->bg->window, FALSE);
+ gtk_widget_map (GTK_WIDGET(dapp->s));
+ gtk_widget_show_all(GTK_WIDGET(dapp->s));
+}
+
+
+/**
+ * Update the background image of the DockApp.
+ *
+ * @param dapp DockappNode to update.
+ */
+void wmdock_update_tile_background(DockappNode *dapp)
+{
+ gtk_widget_realize(GTK_WIDGET(dapp->s));
+
+ if (!dapp->bgimg)
+ return;
+
+ gtk_widget_set_app_paintable(GTK_WIDGET(dapp->s), TRUE);
+ gdk_window_set_back_pixmap(GTK_WIDGET(dapp->s)->window, dapp->bgimg, FALSE);
+
+ if (GTK_WIDGET_FLAGS(GTK_WIDGET(dapp->s)) & GTK_MAPPED)
+ gtk_widget_queue_draw(GTK_WIDGET(dapp->s));
+
+}
+
+
+/**
+ * Get the information if the dockapp the first one.
+ *
+ * @param dapp DockappNode to check.
+ * @return gboolean TRUE if is the first dockapp otherwise false.
+ */
+gboolean wmdock_is_first_dockapp(DockappNode *dapp)
+{
+ if(!dapp)
+ return FALSE;
+
+ if(DOCKAPP(g_list_first(wmdock->dapps)->data) == dapp)
+ return TRUE;
+
+ return FALSE;
+}
+
+
+/**
+ * Get parent dockapp.
+ *
+ * @param dapp Child dockapp.
+ * @return DockAppNode Parent dockapp or null.
+ */
+DockappNode *wmdock_get_parent_dockapp(DockappNode *dapp) {
+ gint i;
+ GList *dapps;
+ DockappNode *_dapp;
+
+ dapps = g_list_first(wmdock->dapps);
+
+ while(dapps) {
+ _dapp = DOCKAPP(dapps->data);
+
+ for(i = 0; i < GLUE_MAX; i++) {
+ if(_dapp->glue[i] == dapp)
+ return _dapp;
+ }
+
+ dapps = g_list_next(dapps);
+ }
+
+ return NULL;
+}
+
+
+/**
+ * This set the tile background image to the DockApp.
+ *
+ * @param dapp The DockApp to set.
+ * @param pm The background image to set.
+ */
+void wmdock_set_tile_background(DockappNode *dapp, GdkPixbuf *pb)
+{
+ GtkFixed *fixed = NULL;
+ GdkGC * gc = NULL;
+
+ if(!(fixed = (GtkFixed *) gtk_widget_get_ancestor(GTK_WIDGET(dapp->s), GTK_TYPE_FIXED)))
+ return;
+
+ if(wmdock->propDispTile == FALSE) {
+ if(!dapp->bg)
+ return;
+
+ gtk_image_clear(GTK_IMAGE(dapp->bg));
+ gtk_image_set_from_pixmap(GTK_IMAGE(dapp->bg), NULL, NULL);
+
+ gdk_pixmap_unref(dapp->bgimg);
+ dapp->bgimg = NULL;
+ gdk_window_clear(GTK_WIDGET(dapp->tile)->window);
+
+ return;
+ }
+
+ debug("dockapp.c: Setup background image (wmdock_set_tile_background).");
+ gtk_widget_realize(GTK_WIDGET(dapp->tile));
+
+ dapp->bgimg = gdk_pixmap_new(GTK_WIDGET(dapp->tile)->window,
+ DEFAULT_DOCKAPP_WIDTH,DEFAULT_DOCKAPP_HEIGHT, -1);
+
+ gc = gdk_gc_new(GTK_WIDGET(dapp->tile)->window);
+ gdk_draw_pixbuf(dapp->bgimg, gc,
+ pb, 0, 0, 0, 0, DEFAULT_DOCKAPP_WIDTH, DEFAULT_DOCKAPP_HEIGHT,
+ GDK_RGB_DITHER_NONE, 0, 0);
+ gdk_gc_unref(gc);
+
+ gtk_image_clear(GTK_IMAGE(dapp->bg));
+ gtk_image_set_from_pixmap(GTK_IMAGE(dapp->bg),dapp->bgimg,NULL);
+
+ if(dapp->s)
+ wmdock_update_tile_background(dapp);
+}
+
+
+/**
+ * Creates a dummy tile without any dockapp in it.
+ *
+ * @return A GTK window widget.
+ */
+GtkWidget *wmdock_create_dummy()
+{
+ GtkWidget *dummy = NULL;
+
+ dummy = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+
+ gtk_window_set_default_size(GTK_WINDOW(dummy), DEFAULT_DOCKAPP_WIDTH,
+ DEFAULT_DOCKAPP_HEIGHT);
+ gtk_container_set_border_width(GTK_CONTAINER(dummy), 0);
+
+ /* Disable window shrinking resizing and growing. */
+ gtk_window_set_policy (GTK_WINDOW(dummy), FALSE, FALSE, FALSE);
+ gtk_window_set_decorated(GTK_WINDOW(dummy), FALSE);
+ gtk_window_set_resizable(GTK_WINDOW(dummy), FALSE);
+ /* Window visible on all workspaces. */
+ gtk_window_stick(GTK_WINDOW(dummy));
+ gtk_window_set_focus_on_map(GTK_WINDOW(dummy), FALSE);
+ /* Hide window from the taskbar and the pager. */
+ gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dummy), TRUE);
+ gtk_window_set_skip_pager_hint(GTK_WINDOW(dummy), TRUE);
+ gtk_window_set_opacity(GTK_WINDOW(dummy), 0.6);
+ gtk_widget_set_size_request(dummy, DEFAULT_DOCKAPP_WIDTH, DEFAULT_DOCKAPP_HEIGHT);
+
+ return (dummy);
+}
+
+
+GtkWidget *wmdock_create_tile_from_socket(DockappNode *dapp)
+{
+ GtkWidget *align = NULL;
+ GtkWidget *tile = NULL;
+ GtkWidget *fixed = NULL;
+
+ if( ! IS_PANELOFF(wmdock)) {
+ /* Default: Put the Dockapp in the XFCE panel. */
+ debug("dockapp.c: DockApp pushed in the XFCE panel.");
+ tile = fixed = gtk_fixed_new();
+ gtk_container_set_border_width(GTK_CONTAINER(fixed),0);
+
+ /* Add the background tile. */
+ dapp->bg = gtk_image_new();
+ gtk_fixed_put(GTK_FIXED(fixed), dapp->bg, 0, 0);
+
+ align = gtk_alignment_new(0.5, 0.5, 0, 0);
+ gtk_widget_set_size_request(GTK_WIDGET(align), DEFAULT_DOCKAPP_WIDTH,
+ DEFAULT_DOCKAPP_HEIGHT);
+ gtk_container_add(GTK_CONTAINER(align), GTK_WIDGET(dapp->s));
+ gtk_fixed_put(GTK_FIXED(fixed), align, 0, 0);
+
+ gtk_widget_show(align);
+ } else {
+ /* If propDispPanelOff is true create a separate window with the
+ * Dockapp in it. It's emulates WindowMaker much more.
+ */
+ debug("dockapp.c: Setup a separate window for the DockApp.");
+ fixed = gtk_fixed_new();
+ gtk_container_set_border_width(GTK_CONTAINER(fixed),0);
+
+ tile = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+
+ gtk_window_set_title(GTK_WINDOW(tile), dapp->name);
+ gtk_window_set_default_size(GTK_WINDOW(tile), DEFAULT_DOCKAPP_WIDTH,
+ DEFAULT_DOCKAPP_HEIGHT);
+ gtk_container_set_border_width(GTK_CONTAINER(tile), 0);
+
+ /* Disable window shrinking resizing and growing. */
+ gtk_window_set_policy (GTK_WINDOW(tile), FALSE, FALSE, FALSE);
+ gtk_window_set_decorated(GTK_WINDOW(tile), FALSE);
+ gtk_window_set_resizable(GTK_WINDOW(tile), FALSE);
+ /* Window visible on all workspaces. */
+ gtk_window_stick(GTK_WINDOW(tile));
+ gtk_window_set_focus_on_map(GTK_WINDOW(tile), FALSE);
+ /* Hide window from the taskbar and the pager. */
+ gtk_window_set_skip_taskbar_hint(GTK_WINDOW(tile), TRUE);
+ gtk_window_set_skip_pager_hint(GTK_WINDOW(tile), TRUE);
+
+ /* Add the background tile. */
+ dapp->bg = gtk_image_new();
+ gtk_fixed_put(GTK_FIXED(fixed), dapp->bg, 0, 0);
+
+ /* Center Dockapp in the window. */
+ align = gtk_alignment_new(0.5, 0.5, 0, 0);
+ gtk_widget_set_size_request(GTK_WIDGET(align), DEFAULT_DOCKAPP_WIDTH,
+ DEFAULT_DOCKAPP_HEIGHT);
+ gtk_window_set_default_size(GTK_WINDOW(tile), DEFAULT_DOCKAPP_WIDTH,
+ DEFAULT_DOCKAPP_HEIGHT);
+ gtk_container_add(GTK_CONTAINER(align), GTK_WIDGET(dapp->s));
+ /* Add the alignment container to the window. */
+ gtk_fixed_put(GTK_FIXED(fixed), align, 0, 0);
+
+ gtk_container_add(GTK_CONTAINER(tile), fixed);
+
+ gtk_widget_show(align);
+ }
+ return (tile);
+}
+
+
+/**
+ * Calculate the position of the DockApp if the PanelOff mode is active.
+ *
+ * @param dapp The dockapp for the move operation.
+ * @param prevDapp The previous dockapp.
+ */
+void wmdock_set_autoposition_dockapp(DockappNode *dapp, DockappNode *prevDapp)
+{
+ gint panelx, panely;
+ gint x, y, i, gluepos = GLUE_MAX;
+
+ if(!IS_PANELOFF(wmdock)) {
+ return;
+ }
+
+ /* Setup the position of the first dockapp. */
+ panelx = panely = x = y = 0;
+
+ /* Initial define the position of the first anchor dockapp. */
+ if(wmdock->anchorPos == -1)
+ wmdock->anchorPos = xfce_panel_plugin_get_screen_position(wmdock->plugin);
+
+ gtk_window_get_position(
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (wmdock->plugin))),
+ &panelx, &panely);
+ if(prevDapp) {
+ for(i = 0; i < GLUE_MAX; i++) {
+ if(prevDapp->glue[i] == dapp) {
+ gluepos = i;
+ break;
+ }
+ }
+ }
+
+ if(gluepos != GLUE_MAX) {
+ wmdock_dockapp_child_pos(prevDapp, gluepos, &x, &y);
+ } else {
+ /* Determine the initial dockapp position. */
+ switch(wmdock->anchorPos) {
+ case XFCE_SCREEN_POSITION_NW_H:
+ case XFCE_SCREEN_POSITION_N:
+ case XFCE_SCREEN_POSITION_NE_H:
+ if(!prevDapp) {
+ x = gdk_screen_width() - DEFAULT_DOCKAPP_WIDTH;
+ y = panelx == 0 ? xfce_panel_plugin_get_size(wmdock->plugin) : 0;
+ } else {
+ wmdock_dockapp_child_pos(prevDapp, GLUE_B, &x, &y);
+ prevDapp->glue[GLUE_B] = dapp;
+ }
+ break;
+
+ case XFCE_SCREEN_POSITION_SW_H:
+ case XFCE_SCREEN_POSITION_S:
+ case XFCE_SCREEN_POSITION_SE_H:
+ if(!prevDapp) {
+ x = gdk_screen_width() - DEFAULT_DOCKAPP_WIDTH;
+ y = panelx == 0 ? panely - DEFAULT_DOCKAPP_HEIGHT : gdk_screen_height() - DEFAULT_DOCKAPP_HEIGHT;
+ } else {
+ wmdock_dockapp_child_pos(prevDapp, GLUE_T, &x, &y);
+ prevDapp->glue[GLUE_T] = dapp;
+ }
+ break;
+ case XFCE_SCREEN_POSITION_NW_V:
+ case XFCE_SCREEN_POSITION_W:
+ case XFCE_SCREEN_POSITION_SW_V:
+ if(!prevDapp) {
+ x = panely == 0 ? xfce_panel_plugin_get_size(wmdock->plugin) : 0;
+ y = 0;
+ } else {
+ wmdock_dockapp_child_pos(prevDapp, GLUE_B, &x, &y);
+ prevDapp->glue[GLUE_B] = dapp;
+ }
+ break;
+ case XFCE_SCREEN_POSITION_NE_V:
+ case XFCE_SCREEN_POSITION_E:
+ case XFCE_SCREEN_POSITION_SE_V:
+ if(!prevDapp) {
+ x = panely == 0 ? gdk_screen_width() - xfce_panel_plugin_get_size(wmdock->plugin) - DEFAULT_DOCKAPP_WIDTH : gdk_screen_width() - DEFAULT_DOCKAPP_WIDTH;
+ y = 0;
+ } else {
+ wmdock_dockapp_child_pos(prevDapp, GLUE_B, &x, &y);
+ prevDapp->glue[GLUE_B] = dapp;
+ }
+ break;
+ default:
+ debug("dockapp.c: Can not determine panel position x = y = 0.");
+ x = y = 0;
+ break;
+ }
+ }
+ gtk_window_move(GTK_WINDOW(dapp->tile), x, y);
+
+ debug("dockapp.c: %d, Panel posx: %d, Panel posy: %d, prevDapp: %s, movex: %d, movey: %d",
+ g_list_length(wmdock->dapps), panelx, panely, prevDapp ? prevDapp->name : "NO", x, y);
+
+}
+
+
+/**
+ * Function order all dockapps (panel off) starting from dapp.
+ *
+ * @param dappStart Dockapp to start with.
+ */
+void wmdock_order_dockapps(DockappNode *dapp)
+{
+ gint i;
+
+ if(! IS_PANELOFF(wmdock) || !dapp)
+ return;
+
+ for(i = 0; i < GLUE_MAX; i++) {
+ wmdock_set_autoposition_dockapp(dapp, wmdock_get_parent_dockapp(dapp));
+
+ debug("dockapp.c: Order dockapp %s", dapp->name);
+ /* Recurse calling wmdock_order_dockapps, to walk the hole tree. */
+ if(dapp->glue[i])
+ wmdock_order_dockapps(dapp->glue[i]);
+ }
+}
diff --git a/panel-plugin/dockapp.h b/panel-plugin/dockapp.h
new file mode 100644
index 0000000..d643015
--- /dev/null
+++ b/panel-plugin/dockapp.h
@@ -0,0 +1,76 @@
+/* wmdock xfce4 plugin by Andre Ellguth
+ * dockapp.h
+ *
+ * $Id: dockapp.h 28 2012-08-12 12:31:28Z ellguth $
+ *
+ * Authors:
+ * Andre Ellguth <ellguth at ibh.de>
+ *
+ * License:
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this package; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __DOCKAPP_H__
+#define __DOCKAPP_H__
+
+#include "wmdock.h"
+
+enum GluePosition {
+ GLUE_T = 1,
+ GLUE_B = 2,
+ GLUE_L = 4,
+ GLUE_R = 8,
+ GLUE_TL = GLUE_T | GLUE_L,
+ GLUE_TR = GLUE_T | GLUE_R,
+ GLUE_BL = GLUE_B | GLUE_L,
+ GLUE_BR = GLUE_B | GLUE_R,
+ GLUE_MAX
+};
+
+typedef struct _dockapp DockappNode;
+struct _dockapp {
+ GtkSocket *s;
+ GdkNativeWindow i;
+ GtkWidget *bg;
+ GdkPixmap *bgimg;
+ GtkWidget *tile;
+ gchar *name;
+ gchar *cmd;
+ DockappNode *glue[GLUE_MAX];
+};
+
+#define DOCKAPP(__dapp) ((DockappNode *) __dapp)
+
+gboolean wmdock_startup_dockapp(const gchar *);
+void wmdock_setupdnd_dockapp(DockappNode *);
+void wmdock_destroy_dockapp(DockappNode *);
+void wmdock_redraw_dockapp(DockappNode *);
+void wmdock_free_dockapp(DockappNode *);
+void wmdock_dapp_closed(GtkSocket *, DockappNode *);
+DockappNode *wmdock_find_startup_dockapp(const gchar *);
+GtkWidget *wmdock_create_tile_from_socket(DockappNode *);
+void wmdock_set_autoposition_dockapp(DockappNode *, DockappNode *);
+void wmdock_refresh_bg(GtkWidget *widget);
+void wmdock_set_tile_background(DockappNode *, GdkPixbuf *);
+void wmdock_update_tile_background(DockappNode *);
+gboolean wmdock_is_first_dockapp(DockappNode *);
+DockappNode *wmdock_get_parent_dockapp(DockappNode *);
+void wmdock_dockapp_tofront(DockappNode *dapp);
+void wmdock_dockapp_paneloff_handler(GtkWidget *, GdkEvent *, DockappNode *);
+void wmdock_remove_anchor_dockapp(DockappNode *, DockappNode *);
+void wmdock_order_dockapps(DockappNode *);
+GtkWidget *wmdock_create_dummy();
+
+#endif /* __DOCKAPP_H__ */
diff --git a/panel-plugin/wmdock.h b/panel-plugin/extern.h
similarity index 53%
copy from panel-plugin/wmdock.h
copy to panel-plugin/extern.h
index f8c42c9..0366f84 100644
--- a/panel-plugin/wmdock.h
+++ b/panel-plugin/extern.h
@@ -1,6 +1,7 @@
/* wmdock xfce4 plugin by Andre Ellguth
+ * extern.h
*
- * $Id$
+ * $Id: extern.h 18 2012-08-06 21:00:29Z ellguth $
*
* Authors:
* Andre Ellguth <ellguth at ibh.de>
@@ -21,40 +22,18 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __WMDOCK_H__
-#define __WMDOCK_H__
+#ifndef __EXTERN_H__
+#define __EXTERN_H__
-#include <gtk/gtk.h>
-#include <libxfce4panel/libxfce4panel.h>
+#include "wmdock.h"
-#define WNCK_I_KNOW_THIS_IS_UNSTABLE
-#include <libwnck/libwnck.h>
+extern WmdockPlugin *wmdock;
+extern GdkPixbuf *gdkPbIcon;
+extern GdkPixbuf *gdkPbTileDefault;
+extern GtkWidget *wmdockIcon;
+extern Atom XfceDockAppAtom;
+extern gchar **rcCmds;
+extern gint rcCmdcnt;
+extern gboolean rcPanelOff;
-typedef struct _dockapp {
- GtkSocket *s;
- GdkNativeWindow i;
- GtkWidget *bg;
- GtkWidget *tile;
- gchar *name;
- gchar *cmd;
-} DockappNode;
-
-typedef struct {
- XfcePanelPlugin *plugin;
-
- GtkWidget *eventBox;
-
- /* Plugin specific definitions */
- GtkWidget *align;
- GtkWidget *box;
- GtkWidget *panelBox;
-
- gboolean propDispTile;
- gboolean propDispPropButton;
- gboolean propDispAddOnlyWM;
- gchar *filterList;
-
- GList *dapps;
-} WmdockPlugin;
-
-#endif /* __WMDOCK_H__ */
+#endif /* __EXTERN_H__ */
diff --git a/panel-plugin/misc.c b/panel-plugin/misc.c
new file mode 100644
index 0000000..1fd0174
--- /dev/null
+++ b/panel-plugin/misc.c
@@ -0,0 +1,181 @@
+/* wmdock xfce4 plugin by Andre Ellguth
+ * Misc functions.
+ *
+ * $Id: misc.c 6 2012-05-23 20:54:15Z ellguth $
+ *
+ * Authors:
+ * Andre Ellguth <ellguth at ibh.de>
+ *
+ * License:
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this package; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+
+#define WNCK_I_KNOW_THIS_IS_UNSTABLE
+#include <libwnck/libwnck.h>
+
+#include <gtk/gtk.h>
+
+#include "extern.h"
+#include "wmdock.h"
+#include "misc.h"
+
+#include "xfce4-wmdock-plugin.xpm"
+
+GdkPixbuf *get_icon_from_xpm_scaled(const char **xpmData, gint width, gint height)
+{
+ GdkPixbuf *gdkPb = NULL;
+ GdkPixbuf *gdkPbScaled = NULL;
+
+ gdkPb = gdk_pixbuf_new_from_xpm_data (xpmData);
+
+ gdkPbScaled = gdk_pixbuf_scale_simple(gdkPb, width, height,
+ GDK_INTERP_BILINEAR);
+
+ g_object_unref (G_OBJECT (gdkPb));
+
+ return(gdkPbScaled);
+}
+
+
+void set_xsmp_support(WnckWindow *w)
+{
+ /* Workaround to skip the XFCE4 session manager. If the window
+ * has this X text property set, the XFCE4 session manager will not
+ * automaticly start the dockapp after startup twice. */
+
+ XTextProperty tp;
+ static Atom _XA_SM_CLIENT_ID = None;
+
+ _XA_SM_CLIENT_ID = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "SM_CLIENT_ID", False);
+
+
+ tp.value = (unsigned char *) strdup("SM_CLIENT_ID");
+ tp.encoding = XA_STRING;
+ tp.format = 8;
+ tp.nitems = 1;
+
+ XSetTextProperty(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
+ wnck_window_get_xid(w),
+ &tp, _XA_SM_CLIENT_ID);
+
+ XFree((unsigned char *)tp.value);
+}
+
+
+gboolean comp_str_with_pattern(const gchar *str, gchar *pattern, gsize s)
+{
+ gboolean r = FALSE;
+
+ if(!str || !pattern) return FALSE;
+
+#if (GLIB_MAJOR_VERSION >= 2 && GLIB_MINOR_VERSION >= 14)
+ GRegex *regex = g_regex_new (pattern, G_REGEX_CASELESS, 0, NULL);
+ if(regex) {
+ r = g_regex_match (regex, str, 0, NULL);
+ g_regex_unref (regex);
+ }
+#else
+ gsize maxsize;
+ gint i;
+
+ maxsize = s > strlen(pattern) ? strlen(pattern) : s;
+
+ for(i=0; i<strlen(str)&&strlen(&str[i]) >= maxsize;i++)
+ if(!g_ascii_strncasecmp (&str[i], pattern, maxsize)) {
+ r = TRUE;
+ break;
+ }
+#endif
+
+ return r;
+}
+
+
+gboolean comp_dockapp_with_filterlist(const gchar *name)
+{
+ gchar **patterns = NULL;
+ gint i=0;
+ gsize s=0;
+ gboolean r = FALSE;
+
+ if(!wmdock->filterList) return FALSE;
+
+ patterns = g_strsplit (wmdock->filterList, ";", 0);
+ if(!patterns) return FALSE;
+ while(patterns[i]) {
+ s = strlen(patterns[i]) > 256 ? 256 : strlen(patterns[i]);
+ if(s > 0 &&
+ (r=comp_str_with_pattern(name, patterns[i], s)) == TRUE)
+ break;
+ i++;
+ }
+
+ g_strfreev(patterns);
+ return r;
+}
+
+
+gboolean has_dockapp_hint(WnckWindow *w)
+{
+ Atom atype;
+ int afmt;
+ unsigned long int nitems;
+ unsigned long int naft;
+ gboolean r = FALSE;
+ unsigned char *dat = NULL;
+
+ gdk_error_trap_push();
+ if (XGetWindowProperty(
+ GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
+ wnck_window_get_xid(w), XfceDockAppAtom, 0, 1, False,
+ XA_CARDINAL, &atype, &afmt, &nitems, &naft, &dat) == Success) {
+ if (nitems==1 && ((long int *) dat)[0]==1) {
+ r = TRUE;
+ }
+ XFree(dat);
+ }
+ XSync(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),False);
+
+ gdk_error_trap_pop();
+
+ return (r);
+}
+
+
+void wmdock_panel_draw_wmdock_icon (gboolean redraw)
+{
+ gdkPbIcon = get_icon_from_xpm_scaled((const char **) xfce4_wmdock_plugin_xpm,
+ xfce_panel_plugin_get_size (wmdock->plugin) - 2,
+ xfce_panel_plugin_get_size (wmdock->plugin) - 2);
+ if(redraw == TRUE && wmdockIcon) {
+ gtk_image_set_from_pixbuf (GTK_IMAGE(wmdockIcon), gdkPbIcon);
+ } else {
+ if(wmdockIcon) gtk_widget_destroy(wmdockIcon);
+ wmdockIcon = gtk_image_new_from_pixbuf (gdkPbIcon);
+
+ gtk_box_pack_start(GTK_BOX(wmdock->box), GTK_WIDGET(wmdockIcon),
+ FALSE, FALSE, 0);
+ }
+ g_object_unref (G_OBJECT (gdkPbIcon));
+
+ gtk_widget_show(GTK_WIDGET(wmdockIcon));
+}
diff --git a/panel-plugin/wmdock.h b/panel-plugin/misc.h
similarity index 53%
copy from panel-plugin/wmdock.h
copy to panel-plugin/misc.h
index f8c42c9..e31a890 100644
--- a/panel-plugin/wmdock.h
+++ b/panel-plugin/misc.h
@@ -1,6 +1,7 @@
/* wmdock xfce4 plugin by Andre Ellguth
+ * misc.h
*
- * $Id$
+ * $Id: misc.h 4 2012-05-23 12:45:49Z ellguth $
*
* Authors:
* Andre Ellguth <ellguth at ibh.de>
@@ -20,41 +21,15 @@
* along with this package; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
-#ifndef __WMDOCK_H__
-#define __WMDOCK_H__
-
-#include <gtk/gtk.h>
-#include <libxfce4panel/libxfce4panel.h>
-
-#define WNCK_I_KNOW_THIS_IS_UNSTABLE
-#include <libwnck/libwnck.h>
-
-typedef struct _dockapp {
- GtkSocket *s;
- GdkNativeWindow i;
- GtkWidget *bg;
- GtkWidget *tile;
- gchar *name;
- gchar *cmd;
-} DockappNode;
-
-typedef struct {
- XfcePanelPlugin *plugin;
-
- GtkWidget *eventBox;
-
- /* Plugin specific definitions */
- GtkWidget *align;
- GtkWidget *box;
- GtkWidget *panelBox;
-
- gboolean propDispTile;
- gboolean propDispPropButton;
- gboolean propDispAddOnlyWM;
- gchar *filterList;
-
- GList *dapps;
-} WmdockPlugin;
-
-#endif /* __WMDOCK_H__ */
+#ifndef __MISC_H__
+#define __MISC_H__
+
+/* Prototypes */
+GdkPixbuf *get_icon_from_xpm_scaled(const char **, gint, gint);
+void set_xsmp_support(WnckWindow *);
+gboolean has_dockapp_hint(WnckWindow *);
+gboolean comp_dockapp_with_filterlist(const gchar *);
+gboolean comp_str_with_pattern(const gchar *, gchar *, gsize);
+void wmdock_panel_draw_wmdock_icon (gboolean redraw);
+
+#endif /* __MISC_H__ */
diff --git a/panel-plugin/props.c b/panel-plugin/props.c
new file mode 100644
index 0000000..004874f
--- /dev/null
+++ b/panel-plugin/props.c
@@ -0,0 +1,514 @@
+/* wmdock xfce4 plugin by Andre Ellguth
+ * Properties dialog.
+ *
+ * $Id: props.c 23 2012-08-09 19:39:15Z ellguth $
+ *
+ * Authors:
+ * Andre Ellguth <ellguth at ibh.de>
+ *
+ * License:
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this package; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <gtk/gtk.h>
+#include <libxfce4util/libxfce4util.h>
+#include <libxfcegui4/libxfcegui4.h>
+#include <libxfce4panel/libxfce4panel.h>
+
+#include "extern.h"
+#include "props.h"
+#include "wmdock.h"
+#include "debug.h"
+#include "dockapp.h"
+#include "misc.h"
+
+#include "xfce4-wmdock-plugin.xpm"
+
+/* Properties dialog */
+static struct {
+ GtkWidget *dlg;
+ GtkWidget *vbox, *vbox2, *vboxGeneral, *vboxDetect;
+ GtkWidget *hbox;
+ GtkWidget *frmGeneral, *frmDetect;
+ GtkWidget *lblSel, *lblCmd;
+ GtkWidget *chkDispTile, *chkPropButton, *chkAddOnlyWM, *chkPanelOff;
+ GtkWidget *imageContainer, *container;
+ GtkWidget *imageTile, *image;
+ GtkWidget *txtCmd;
+ GtkWidget *cbx;
+ GtkWidget *btnMoveUp, *btnMoveDown, *txtPatterns;
+} prop;
+
+static GtkWidget *btnProperties = NULL;
+
+
+static void wmdock_info_dialog_response (GtkWidget *gtkDlg, gint response)
+{
+ gtk_widget_destroy (gtkDlg);
+}
+
+
+static void wmdock_properties_fillcmbx(DockappNode *dapp, GtkWidget *gtkComboBox)
+{
+
+ if(gtkComboBox) {
+ debug("props.c: %s append to list", dapp->name);
+ gtk_combo_box_append_text (GTK_COMBO_BOX(gtkComboBox), dapp->name);
+ }
+}
+
+
+static void wmdock_properties_chkdisptile(GtkToggleButton *gtkChkDispTile, gpointer user_data)
+{
+ wmdock->propDispTile = gtk_toggle_button_get_active(gtkChkDispTile);
+
+ g_list_foreach(wmdock->dapps, (GFunc)wmdock_redraw_dockapp, NULL);
+ gtk_widget_show_all(GTK_WIDGET(wmdock->box));
+}
+
+
+static void wmdock_properties_chkpropbtn(GtkToggleButton *gtkChkPropButton, gpointer user_data)
+{
+ wmdock->propDispPropButton = gtk_toggle_button_get_active(gtkChkPropButton);
+
+ if(wmdock->propDispPropButton == FALSE) {
+ if(btnProperties) gtk_widget_destroy(btnProperties);
+ btnProperties = NULL;
+ }
+ else
+ wmdock_panel_draw_properties_button ();
+}
+
+
+static void wmdock_properties_chkaddonlywm(GtkToggleButton *gtkChkAddOnlyWM, gpointer user_data)
+{
+ wmdock->propDispAddOnlyWM = gtk_toggle_button_get_active(gtkChkAddOnlyWM);
+ gtk_widget_set_sensitive (GTK_WIDGET (prop.txtPatterns),
+ wmdock->propDispAddOnlyWM);
+}
+
+
+static void wmdock_properties_chkpaneloff(GtkToggleButton *gtkChkPanelOff, gpointer user_data)
+{
+ GtkWidget *gtkDlg;
+
+ rcPanelOff = gtk_toggle_button_get_active(gtkChkPanelOff);
+
+ if(g_list_length(wmdock->dapps)) {
+ if(rcPanelOff == TRUE)
+ wmdock->anchorPos = xfce_panel_plugin_get_screen_position(wmdock->plugin);
+
+ gtkDlg = gtk_message_dialog_new(GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (wmdock->plugin))),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("Changes will take effect when you restart XFCE!"));
+ g_signal_connect (gtkDlg, "response", G_CALLBACK (wmdock_info_dialog_response), NULL);
+ gtk_widget_show_all (gtkDlg);
+ } else {
+ /* If no dockapp is started enable/disable panel off mode. */
+ wmdock->propPanelOff = rcPanelOff;
+ }
+}
+
+
+static gboolean wmdock_properties_refresh_dapp_icon()
+{
+ GdkPixmap *pm = NULL;
+ DockappNode *dapp = NULL;
+ gboolean ret;
+
+ if(prop.dlg && prop.image && prop.cbx) {
+ dapp = DOCKAPP(g_list_nth_data(wmdock->dapps,
+ gtk_combo_box_get_active(GTK_COMBO_BOX(prop.cbx))));
+ if(dapp) {
+ pm = gdk_pixmap_foreign_new (dapp->i);
+ if(pm) {
+ gtk_image_set_from_pixmap (GTK_IMAGE(prop.image), pm, NULL);
+ gtk_widget_show(prop.image);
+ g_object_unref (G_OBJECT(pm));
+ }
+ else {
+ gtk_image_set_from_pixbuf (GTK_IMAGE(prop.image), gdkPbTileDefault);
+ gtk_widget_show(prop.image);
+ /* Check if the window is gone. */
+ if(!wnck_window_get (dapp->i)) {
+ ret = FALSE;
+ wmdock_dapp_closed(dapp->s, dapp);
+ }
+ }
+ }
+
+ ret = TRUE;
+ } else {
+ ret = FALSE;
+ debug("props.c: wmdock_properties_refresh_dapp_icon status changed to FALSE");
+ }
+
+ return (ret);
+}
+
+
+static void wmdock_properties_changed (GtkWidget *gtkComboBox, GtkWidget *gtkTxtCmd)
+{
+ DockappNode *dapp = NULL;
+
+
+ dapp = DOCKAPP(g_list_nth_data(wmdock->dapps, gtk_combo_box_get_active(GTK_COMBO_BOX(gtkComboBox))));
+ if(dapp) {
+ debug("props.c: changed, %s selected:", dapp->name);
+
+ gtk_entry_set_text(GTK_ENTRY(gtkTxtCmd), dapp->cmd);
+
+ wmdock_properties_refresh_dapp_icon();
+ }
+}
+
+
+static void wmdock_properties_moveup (GtkWidget *gtkBtnMoveUp, GtkWidget *gtkComboBox)
+{
+ DockappNode *dapp = NULL;
+ gint pos;
+
+ pos = gtk_combo_box_get_active(GTK_COMBO_BOX(gtkComboBox));
+
+ if(g_list_length(wmdock->dapps) > 1 && pos > 0) {
+ dapp = DOCKAPP(g_list_nth_data(wmdock->dapps, pos));
+
+ if(dapp) {
+ wmdock->dapps = g_list_remove_all(wmdock->dapps, dapp);
+ wmdock->dapps = g_list_insert(wmdock->dapps, dapp, pos - 1);
+ gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkComboBox), pos);
+ gtk_combo_box_insert_text(GTK_COMBO_BOX(gtkComboBox), pos - 1, dapp->name);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(gtkComboBox), pos - 1);
+ gtk_box_reorder_child(GTK_BOX(wmdock->box), GTK_WIDGET(dapp->tile), pos - 1);
+
+ g_list_foreach(wmdock->dapps, (GFunc)wmdock_redraw_dockapp, NULL);
+ }
+ }
+}
+
+
+static void wmdock_properties_movedown (GtkWidget *gtkBtnMoveDown, GtkWidget *gtkComboBox)
+{
+ DockappNode *dapp = NULL;
+ gint pos;
+
+ pos = gtk_combo_box_get_active(GTK_COMBO_BOX(gtkComboBox));
+
+ if(g_list_length(wmdock->dapps) > 1 && pos < g_list_length(wmdock->dapps) - 1) {
+ dapp = DOCKAPP(g_list_nth_data(wmdock->dapps, pos));
+
+ if(dapp) {
+ wmdock->dapps = g_list_remove_all(wmdock->dapps, dapp);
+ wmdock->dapps = g_list_insert(wmdock->dapps, dapp, pos + 1);
+ gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkComboBox), pos);
+ gtk_combo_box_insert_text(GTK_COMBO_BOX(gtkComboBox), pos + 1, dapp->name);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(gtkComboBox), pos + 1);
+ gtk_box_reorder_child(GTK_BOX(wmdock->box), GTK_WIDGET(dapp->tile), pos + 1);
+
+ g_list_foreach(wmdock->dapps, (GFunc)wmdock_redraw_dockapp, NULL);
+ }
+ }
+}
+
+
+static void wmdock_properties_savecmd (GtkWidget *gtkTxtCmd, GdkEventKey *event, GtkWidget *gtkComboBox)
+{
+ DockappNode *dapp = NULL;
+ gint pos;
+
+ pos = gtk_combo_box_get_active(GTK_COMBO_BOX(gtkComboBox));
+
+ dapp = DOCKAPP(g_list_nth_data(wmdock->dapps, pos));
+ if(dapp) {
+ g_free(dapp->cmd);
+ dapp->cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtkTxtCmd)));
+ }
+}
+
+
+static void wmdock_properties_dialog_response (GtkWidget *gtkDlg, gint response)
+{
+ DockappNode *dapp = NULL;
+ gint pos;
+
+ if(!gtkDlg) return;
+
+ switch(response) {
+ case GTK_RESPONSE_NO: /* Remove dockapp */
+ if(g_list_length(wmdock->dapps) > 0 && prop.cbx) {
+ pos = gtk_combo_box_get_active(GTK_COMBO_BOX(prop.cbx));
+
+ dapp = DOCKAPP(g_list_nth_data(wmdock->dapps, pos));
+ if(dapp)
+ wmdock_destroy_dockapp(dapp);
+ }
+ break;
+
+ default:
+ /* Backup the value of the dockapp filter. */
+ if(wmdock->propDispAddOnlyWM) {
+ if(wmdock->filterList) g_free(wmdock->filterList);
+ wmdock->filterList = g_strdup(gtk_entry_get_text(GTK_ENTRY(prop.txtPatterns)));
+ }
+
+ xfce_panel_plugin_unblock_menu (wmdock->plugin);
+ gtk_widget_destroy (gtkDlg);
+
+ debug("props.c: properties dlg closed");
+
+ prop.dlg = prop.cbx = prop.txtCmd = prop.image = NULL;
+ break;
+ }
+}
+
+
+static void wmdock_properties_dialog_called_from_widget(GtkWidget *widget, XfcePanelPlugin *plugin)
+{
+ wmdock_properties_dialog(plugin);
+}
+
+
+void wmdock_panel_draw_properties_button ()
+{
+ if(!btnProperties && wmdock->propDispPropButton == TRUE) {
+ btnProperties = xfce_create_panel_button();
+ gtk_box_pack_start(GTK_BOX(wmdock->panelBox),
+ btnProperties, FALSE, FALSE, 0);
+ gtk_box_reorder_child(GTK_BOX(wmdock->panelBox), btnProperties, 0);
+
+ g_signal_connect (G_OBJECT(btnProperties), "pressed",
+ G_CALLBACK (wmdock_properties_dialog_called_from_widget),
+ wmdock->plugin);
+
+ gtk_widget_show(GTK_WIDGET(btnProperties));
+ }
+}
+
+
+void wmdock_error_dialog_response (GtkWidget *gtkDlg, gint response)
+{
+ gtk_widget_destroy (gtkDlg);
+}
+
+
+void wmdock_refresh_properties_dialog()
+{
+ gint pos = 0;
+
+ if(!prop.dlg || !prop.cbx || !prop.txtCmd) return;
+
+ /* Cleanup the old list */
+ while((pos = gtk_combo_box_get_active (GTK_COMBO_BOX(prop.cbx)))
+ != -1) {
+ gtk_combo_box_remove_text(GTK_COMBO_BOX(prop.cbx), pos);
+ gtk_combo_box_set_active (GTK_COMBO_BOX(prop.cbx), 0);
+ }
+
+ gtk_combo_box_popdown (GTK_COMBO_BOX(prop.cbx));
+ if(g_list_length(wmdock->dapps) > 0) {
+ gtk_widget_set_sensitive (prop.txtCmd, TRUE);
+
+ g_list_foreach(wmdock->dapps, (GFunc) wmdock_properties_fillcmbx, prop.cbx);
+
+
+ } else {
+ gtk_combo_box_append_text (GTK_COMBO_BOX(prop.cbx),
+ _("No dockapp is running!"));
+
+ gtk_widget_set_state(prop.txtCmd, GTK_STATE_INSENSITIVE);
+ gtk_entry_set_text(GTK_ENTRY(prop.txtCmd), "");
+
+ gdkPbIcon = gdk_pixbuf_new_from_xpm_data((const char**)
+ xfce4_wmdock_plugin_xpm);
+
+ gtk_image_set_from_pixbuf (GTK_IMAGE(prop.image), gdkPbIcon);
+
+ g_object_unref (G_OBJECT (gdkPbIcon));
+ }
+
+ gtk_combo_box_set_active(GTK_COMBO_BOX(prop.cbx), 0);
+
+ gtk_widget_show (prop.image);
+ gtk_widget_show (prop.cbx);
+ gtk_widget_show (prop.txtCmd);
+}
+
+
+void wmdock_properties_dialog(XfcePanelPlugin *plugin)
+{
+ if(prop.dlg) return; /* Return if properties dialog is already open. */
+
+ memset(&prop, 0, sizeof(prop));
+ xfce_panel_plugin_block_menu (plugin);
+
+ /* Create the configure dialog. */
+ prop.dlg = xfce_titled_dialog_new_with_buttons (_("WMdock"),
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))),
+ GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
+ _("Remove dockapp"), GTK_RESPONSE_NO,
+ GTK_STOCK_CLOSE, GTK_RESPONSE_OK,
+ NULL);
+
+ gtk_window_set_position (GTK_WINDOW (prop.dlg), GTK_WIN_POS_CENTER);
+ gtk_window_set_icon_name (GTK_WINDOW (prop.dlg), "xfce4-settings");
+
+ g_signal_connect (prop.dlg, "response",
+ G_CALLBACK (wmdock_properties_dialog_response),
+ NULL);
+
+ /* Create the layout containers. */
+ prop.hbox = gtk_hbox_new(FALSE, 6);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (prop.dlg)->vbox), prop.hbox, FALSE, FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (prop.hbox), 4);
+
+ prop.frmGeneral = gtk_frame_new(_("General settings"));
+ prop.frmDetect = gtk_frame_new(_("Dockapp detection"));
+ prop.vboxGeneral = gtk_vbox_new(FALSE, 6);
+ prop.vboxDetect = gtk_vbox_new(FALSE, 6);
+
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (prop.dlg)->vbox), prop.frmGeneral,
+ FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (prop.dlg)->vbox), prop.frmDetect,
+ FALSE, FALSE, 0);
+ gtk_container_set_border_width (GTK_CONTAINER (prop.vboxGeneral), 4);
+ gtk_container_set_border_width (GTK_CONTAINER (prop.vboxDetect), 4);
+
+ prop.vbox = gtk_vbox_new(FALSE, 4);
+ prop.vbox2 = gtk_vbox_new(FALSE, 4);
+ gtk_container_set_border_width (GTK_CONTAINER (prop.vbox), 2);
+ gtk_container_set_border_width (GTK_CONTAINER (prop.vbox2), 2);
+ gtk_box_pack_start (GTK_BOX (prop.hbox), prop.vbox, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (prop.hbox), prop.vbox2, FALSE, FALSE, 0);
+
+
+ prop.imageContainer = gtk_alignment_new(0.5, 0.5, 0, 0);
+ gtk_widget_set_size_request(GTK_WIDGET(prop.imageContainer),
+ DEFAULT_DOCKAPP_WIDTH,
+ DEFAULT_DOCKAPP_HEIGHT);
+ prop.container = gtk_fixed_new();
+
+ gdkPbIcon = gdk_pixbuf_new_from_xpm_data((const char**)
+ xfce4_wmdock_plugin_xpm);
+
+ prop.imageTile = gtk_image_new_from_pixbuf(gdkPbTileDefault);
+ prop.image = gtk_image_new_from_pixbuf (gdkPbIcon);
+
+ g_object_unref (G_OBJECT (gdkPbIcon));
+
+ gtk_container_add(GTK_CONTAINER(prop.imageContainer), prop.image);
+ gtk_container_add(GTK_CONTAINER(prop.container), prop.imageTile);
+ gtk_container_add(GTK_CONTAINER(prop.container), prop.imageContainer);
+
+
+ gtk_box_pack_start (GTK_BOX(prop.vbox), GTK_WIDGET (prop.container),
+ FALSE, FALSE, 0);
+
+ prop.btnMoveUp = xfce_arrow_button_new (GTK_ARROW_UP);
+ prop.btnMoveDown = xfce_arrow_button_new (GTK_ARROW_DOWN);
+
+ if(!IS_PANELOFF(wmdock)) {
+ gtk_box_pack_start (GTK_BOX(prop.vbox), GTK_WIDGET (prop.btnMoveUp), FALSE,
+ FALSE, 0);
+ gtk_box_pack_start (GTK_BOX(prop.vbox), GTK_WIDGET (prop.btnMoveDown), FALSE,
+ FALSE, 0);
+ }
+
+ prop.lblSel = gtk_label_new (_("Select dockapp to configure:"));
+ gtk_misc_set_alignment (GTK_MISC (prop.lblSel), 0, 0);
+ gtk_box_pack_start (GTK_BOX(prop.vbox2), prop.lblSel, FALSE, FALSE, 0);
+
+ /* Create the dockapp chooser combobox */
+ prop.cbx = gtk_combo_box_new_text();
+
+ gtk_box_pack_start (GTK_BOX (prop.vbox2), prop.cbx, FALSE, TRUE, 0);
+
+ prop.lblCmd = gtk_label_new (_("Shell command:"));
+ gtk_misc_set_alignment (GTK_MISC (prop.lblCmd), 0, 0);
+ gtk_box_pack_start (GTK_BOX(prop.vbox2), prop.lblCmd, FALSE, FALSE, 0);
+ prop.txtCmd = gtk_entry_new();
+ if(g_list_length(wmdock->dapps) > 0) {
+ gtk_editable_set_editable(GTK_EDITABLE(prop.txtCmd), TRUE);
+ } else {
+ gtk_editable_set_editable(GTK_EDITABLE(prop.txtCmd), FALSE);
+ }
+ gtk_box_pack_start (GTK_BOX(prop.vbox2), prop.txtCmd, FALSE, FALSE, 0);
+
+ prop.chkDispTile = gtk_check_button_new_with_label(_("Display tile in the background."));
+ prop.chkPropButton = gtk_check_button_new_with_label(_("Display a separate WMdock properties\nbutton in the panel."));
+ prop.chkAddOnlyWM = gtk_check_button_new_with_label(_("Add only dockapps which start with\npattern in list. (e.g.: ^wm;^as)"));
+ prop.chkPanelOff = gtk_check_button_new_with_label(_("Don't use the XFCE panel for the dockapps."));
+ prop.txtPatterns = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(prop.txtPatterns), wmdock->filterList);
+ gtk_widget_set_sensitive (GTK_WIDGET (prop.txtPatterns),
+ wmdock->propDispAddOnlyWM);
+
+ gtk_toggle_button_set_active((GtkToggleButton *) prop.chkDispTile,
+ wmdock->propDispTile);
+ gtk_toggle_button_set_active((GtkToggleButton *) prop.chkPropButton,
+ wmdock->propDispPropButton);
+ gtk_toggle_button_set_active((GtkToggleButton *) prop.chkAddOnlyWM,
+ wmdock->propDispAddOnlyWM);
+ gtk_toggle_button_set_active((GtkToggleButton *) prop.chkPanelOff,
+ rcPanelOff);
+
+ gtk_container_add(GTK_CONTAINER(prop.frmGeneral), prop.vboxGeneral);
+ gtk_container_add(GTK_CONTAINER(prop.frmDetect), prop.vboxDetect);
+ gtk_box_pack_start (GTK_BOX(prop.vboxGeneral), prop.chkPanelOff,
+ FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX(prop.vboxGeneral), prop.chkDispTile,
+ FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX(prop.vboxGeneral), prop.chkPropButton,
+ FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX(prop.vboxDetect), prop.chkAddOnlyWM,
+ FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX(prop.vboxDetect), prop.txtPatterns,
+ FALSE, FALSE, 0);
+
+
+ /* Fill the dockapp chooser with entries. */
+ wmdock_refresh_properties_dialog();
+
+ /* Connect some signals to the dialog widgets */
+ g_signal_connect(G_OBJECT(prop.cbx), "changed",
+ G_CALLBACK(wmdock_properties_changed), prop.txtCmd);
+ g_signal_connect(G_OBJECT(prop.txtCmd), "key-release-event",
+ G_CALLBACK(wmdock_properties_savecmd), prop.cbx);
+ g_signal_connect(G_OBJECT(prop.btnMoveUp), "pressed",
+ G_CALLBACK(wmdock_properties_moveup), prop.cbx);
+ g_signal_connect(G_OBJECT(prop.btnMoveDown), "pressed",
+ G_CALLBACK(wmdock_properties_movedown), prop.cbx);
+ g_signal_connect(G_OBJECT(prop.chkDispTile), "toggled",
+ G_CALLBACK(wmdock_properties_chkdisptile), NULL);
+ g_signal_connect(G_OBJECT(prop.chkPanelOff), "toggled",
+ G_CALLBACK(wmdock_properties_chkpaneloff), NULL);
+ g_signal_connect(G_OBJECT(prop.chkPropButton), "toggled",
+ G_CALLBACK(wmdock_properties_chkpropbtn), NULL);
+ g_signal_connect(G_OBJECT(prop.chkAddOnlyWM), "toggled",
+ G_CALLBACK(wmdock_properties_chkaddonlywm), NULL);
+
+ g_timeout_add (500, wmdock_properties_refresh_dapp_icon, NULL);
+
+ if(g_list_length(wmdock->dapps) > 0)
+ wmdock_properties_changed(prop.cbx, prop.txtCmd);
+
+ gtk_widget_show_all (prop.dlg);
+}
diff --git a/panel-plugin/wmdock.h b/panel-plugin/props.h
similarity index 53%
copy from panel-plugin/wmdock.h
copy to panel-plugin/props.h
index f8c42c9..225d5c3 100644
--- a/panel-plugin/wmdock.h
+++ b/panel-plugin/props.h
@@ -1,6 +1,7 @@
/* wmdock xfce4 plugin by Andre Ellguth
+ * Properties dialog - Header.
*
- * $Id$
+ * $Id: props.h 4 2012-05-23 12:45:49Z ellguth $
*
* Authors:
* Andre Ellguth <ellguth at ibh.de>
@@ -21,40 +22,13 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __WMDOCK_H__
-#define __WMDOCK_H__
+#ifndef __PROPS_H__
+#define __PROPS_H__
-#include <gtk/gtk.h>
-#include <libxfce4panel/libxfce4panel.h>
+/* prototypes */
+void wmdock_properties_dialog(XfcePanelPlugin *plugin);
+void wmdock_refresh_properties_dialog();
+void wmdock_panel_draw_properties_button();
+void wmdock_error_dialog_response (GtkWidget *, gint);
-#define WNCK_I_KNOW_THIS_IS_UNSTABLE
-#include <libwnck/libwnck.h>
-
-typedef struct _dockapp {
- GtkSocket *s;
- GdkNativeWindow i;
- GtkWidget *bg;
- GtkWidget *tile;
- gchar *name;
- gchar *cmd;
-} DockappNode;
-
-typedef struct {
- XfcePanelPlugin *plugin;
-
- GtkWidget *eventBox;
-
- /* Plugin specific definitions */
- GtkWidget *align;
- GtkWidget *box;
- GtkWidget *panelBox;
-
- gboolean propDispTile;
- gboolean propDispPropButton;
- gboolean propDispAddOnlyWM;
- gchar *filterList;
-
- GList *dapps;
-} WmdockPlugin;
-
-#endif /* __WMDOCK_H__ */
+#endif /* __PROPS_H__ */
diff --git a/panel-plugin/rcfile.c b/panel-plugin/rcfile.c
new file mode 100644
index 0000000..3b3a69b
--- /dev/null
+++ b/panel-plugin/rcfile.c
@@ -0,0 +1,159 @@
+/* wmdock xfce4 plugin by Andre Ellguth
+ * Configuration file handling.
+ *
+ * $Id: rcfile.c 23 2012-08-09 19:39:15Z ellguth $
+ *
+ * Authors:
+ * Andre Ellguth <ellguth at ibh.de>
+ *
+ * License:
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this package; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
+
+#define WNCK_I_KNOW_THIS_IS_UNSTABLE
+#include <libwnck/libwnck.h>
+
+#include <gtk/gtk.h>
+#include <libxfce4util/libxfce4util.h>
+#include <libxfcegui4/libxfcegui4.h>
+#include <libxfce4panel/libxfce4panel.h>
+
+#include "extern.h"
+#include "rcfile.h"
+#include "wmdock.h"
+#include "debug.h"
+#include "dockapp.h"
+#include "props.h"
+
+
+void wmdock_read_rc_file (XfcePanelPlugin *plugin)
+{
+ gchar *file = NULL;
+ XfceRc *rc = NULL;
+ gint i;
+ GtkWidget *gtkDlg;
+ DockappNode *dapp = NULL;
+
+ if (!(file = xfce_panel_plugin_lookup_rc_file (plugin))) return;
+
+ rc = xfce_rc_simple_open (file, TRUE);
+ g_free(file);
+
+ if(!rc) return;
+
+ rcCmds = xfce_rc_read_list_entry(rc, "cmds", ";");
+ rcCmdcnt = xfce_rc_read_int_entry(rc, "cmdcnt", 0);
+ wmdock->propDispTile = xfce_rc_read_bool_entry (rc, "disptile", TRUE);
+ wmdock->propDispPropButton = xfce_rc_read_bool_entry (rc, "disppropbtn", FALSE);
+ wmdock->propDispAddOnlyWM = xfce_rc_read_bool_entry (rc, "dispaddonlywm", TRUE);
+ if(wmdock->filterList) g_free(wmdock->filterList);
+ wmdock->filterList = g_strdup(xfce_rc_read_entry (rc, "dafilter", DOCKAPP_FILTER_PATTERN));
+ /* TODO: Set panel off to FALSE. */
+ rcPanelOff = wmdock->propPanelOff = xfce_rc_read_bool_entry (rc, "paneloff", TRUE);
+ wmdock->anchorPos = xfce_rc_read_int_entry(rc, "anchorpos", -1);
+
+ if(G_LIKELY(rcCmds != NULL)) {
+ /* Wait 5 seconds as workaround for double XMap problems. */
+ g_usleep(5 * G_USEC_PER_SEC);
+
+ for (i = 0; i <= rcCmdcnt; i++) {
+ debug("rcfile.c: config will start: %s\n", rcCmds[i]);
+
+ if(!rcCmds[i]) continue;
+ if(wmdock_startup_dockapp(rcCmds[i]) != TRUE) {
+ gtkDlg = gtk_message_dialog_new(GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Failed to start %s!"),
+ rcCmds[i]);
+ g_signal_connect (gtkDlg, "response", G_CALLBACK (wmdock_error_dialog_response), NULL);
+ gtk_widget_show_all (gtkDlg);
+ } else {
+ /* Create some dummy widget entries to locate the right position on
+ * window swallow up.
+ */
+
+ dapp = g_new0(DockappNode, 1);
+ dapp->name = NULL;
+ dapp->cmd = rcCmds[i];
+
+ dapp->s = GTK_SOCKET(gtk_socket_new());
+ dapp->tile = wmdock_create_tile_from_socket(dapp);
+
+ if( ! IS_PANELOFF(wmdock) ) {
+ gtk_box_pack_start(GTK_BOX(wmdock->box), GTK_WIDGET(dapp->tile),
+ FALSE, FALSE, 0);
+ }
+
+ wmdock->dapps=g_list_append(wmdock->dapps, dapp);
+ }
+ }
+ }
+
+ xfce_rc_close (rc);
+}
+
+
+void wmdock_write_rc_file (XfcePanelPlugin *plugin)
+{
+ gchar *file;
+ XfceRc *rc;
+ gchar **cmds;
+ DockappNode *dapp = NULL;
+ gint i;
+
+ if (!(file = xfce_panel_plugin_save_location (plugin, TRUE))) return;
+
+ rc = xfce_rc_simple_open (file, FALSE);
+ g_free (file);
+
+ if (!rc) return;
+
+ if(g_list_length (wmdock->dapps) > 0) {
+ cmds = g_malloc(sizeof (gchar *) * (g_list_length (wmdock->dapps) + 1));
+
+ for(i = 0; i < g_list_length(wmdock->dapps); i++) {
+ dapp = DOCKAPP(g_list_nth_data(wmdock->dapps, i));
+ if(dapp) {
+ if(dapp->name && dapp->cmd)
+ cmds[i] = g_strdup(dapp->cmd);
+ }
+ }
+ /* Workaround for a xfce bug in xfce_rc_read_list_entry */
+ cmds[i] = NULL;
+
+ xfce_rc_write_list_entry(rc, "cmds", cmds, ";");
+
+ g_strfreev(cmds);
+
+ xfce_rc_write_int_entry (rc, "cmdcnt", g_list_length (wmdock->dapps));
+ xfce_rc_write_bool_entry (rc, "disptile", wmdock->propDispTile);
+ xfce_rc_write_bool_entry (rc, "disppropbtn", wmdock->propDispPropButton);
+ xfce_rc_write_bool_entry (rc, "dispaddonlywm", wmdock->propDispAddOnlyWM);
+ xfce_rc_write_bool_entry (rc, "paneloff", rcPanelOff);
+ xfce_rc_write_entry(rc, "dafilter", wmdock->filterList);
+ xfce_rc_write_int_entry (rc, "anchorpos", wmdock->anchorPos);
+ }
+
+ xfce_rc_close(rc);
+}
diff --git a/panel-plugin/wmdock.h b/panel-plugin/rcfile.h
similarity index 53%
copy from panel-plugin/wmdock.h
copy to panel-plugin/rcfile.h
index f8c42c9..e529611 100644
--- a/panel-plugin/wmdock.h
+++ b/panel-plugin/rcfile.h
@@ -1,6 +1,7 @@
/* wmdock xfce4 plugin by Andre Ellguth
+ * rcfile.h
*
- * $Id$
+ * $Id: rcfile.h 4 2012-05-23 12:45:49Z ellguth $
*
* Authors:
* Andre Ellguth <ellguth at ibh.de>
@@ -21,40 +22,11 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef __WMDOCK_H__
-#define __WMDOCK_H__
+#ifndef __RCFILE_H__
+#define __RCFILE_H__
-#include <gtk/gtk.h>
-#include <libxfce4panel/libxfce4panel.h>
+/* Prototypes */
+void wmdock_read_rc_file (XfcePanelPlugin *);
+void wmdock_write_rc_file (XfcePanelPlugin *);
-#define WNCK_I_KNOW_THIS_IS_UNSTABLE
-#include <libwnck/libwnck.h>
-
-typedef struct _dockapp {
- GtkSocket *s;
- GdkNativeWindow i;
- GtkWidget *bg;
- GtkWidget *tile;
- gchar *name;
- gchar *cmd;
-} DockappNode;
-
-typedef struct {
- XfcePanelPlugin *plugin;
-
- GtkWidget *eventBox;
-
- /* Plugin specific definitions */
- GtkWidget *align;
- GtkWidget *box;
- GtkWidget *panelBox;
-
- gboolean propDispTile;
- gboolean propDispPropButton;
- gboolean propDispAddOnlyWM;
- gchar *filterList;
-
- GList *dapps;
-} WmdockPlugin;
-
-#endif /* __WMDOCK_H__ */
+#endif /* __RCFILE_H__ */
diff --git a/panel-plugin/wmdock.c b/panel-plugin/wmdock.c
index a144cb0..24ee42d 100644
--- a/panel-plugin/wmdock.c
+++ b/panel-plugin/wmdock.c
@@ -1,6 +1,6 @@
/* wmdock xfce4 plugin by Andre Ellguth
*
- * $Id$
+ * $Id: wmdock.c 23 2012-08-09 19:39:15Z ellguth $
*
* Authors:
* Andre Ellguth <ellguth at ibh.de>
@@ -37,1403 +37,157 @@
#include <libxfce4panel/libxfce4panel.h>
#include "wmdock.h"
-#include "xfce4-wmdock-plugin.xpm"
-#include "tile.xpm"
+#include "catchwindow.h"
+#include "debug.h"
+#include "dnd.h"
+#include "dockapp.h"
+#include "misc.h"
+#include "props.h"
+#include "rcfile.h"
+#include "tile.xpm"
-#define DEFAULT_DOCKAPP_WIDTH 64
-#define DEFAULT_DOCKAPP_HEIGHT 64
-#define FONT_WIDTH 4
-#define MAX_WAITCNT 10000
+#define FONT_WIDTH 4
+#define MAX_WAITCNT 10000
#define WAITCNT_TIMEOUT 1000000
-#define BUF_MAX 4096
-/* Default filter for dockapps. All dockapps starting with "wm" or "as". */
-#define DOCKAPP_FILTER_PATTERN "^wm;^as"
-
-#define _BYTE 8
Atom XfceDockAppAtom;
-GtkWidget *wmdockIcon = NULL;
-GtkWidget *btnProperties = NULL;
-DockappNode *dappProperties = NULL;
-GdkPixmap *gdkPmTile = NULL;
-GdkPixbuf *gdkPbIcon = NULL;
-WmdockPlugin *wmdock = NULL;
-gchar **rcCmds = NULL;
-gint rcCmdcnt = 0;
-
-
-/* Properties dialog */
-static struct {
- GtkWidget *dlg;
- GtkWidget *vbox, *vbox2, *vboxGeneral, *vboxDetect;
- GtkWidget *hbox;
- GtkWidget *frmGeneral, *frmDetect;
- GtkWidget *lblSel, *lblCmd;
- GtkWidget *chkDispTile, *chkPropButton, *chkAddOnlyWM;
- GtkWidget *imageContainer, *container;
- GtkWidget *imageTile, *image;
- GtkWidget *txtCmd;
- GtkWidget *cbx;
- GtkWidget *btnMoveUp, *btnMoveDown, *txtPatterns;
-} prop;
-
-
-static GtkTargetEntry targetList[] = {
- { "INTEGER", 0, 0 }
-};
-static guint nTargets = G_N_ELEMENTS (targetList);
-
-
-/* Prototypes */
-static void wmdock_properties_dialog_called_from_widget(GtkWidget *, XfcePanelPlugin *);
-static void wmdock_properties_dialog(XfcePanelPlugin *);
-static void wmdock_redraw_dockapp(DockappNode *);
-static void wmdock_destroy_dockapp(DockappNode *);
-
-
-#ifdef DEBUG
-/* fp needed for debug */
-FILE *fp = (FILE *) NULL;
-#endif
-
-
-static gboolean comp_str_with_pattern(const gchar *str, gchar *pattern, gsize s)
-{
- gboolean r = FALSE;
-
- if(!str || !pattern) return FALSE;
-
-#if (GLIB_MAJOR_VERSION >= 2 && GLIB_MINOR_VERSION >= 14)
- GRegex *regex = g_regex_new (pattern, G_REGEX_CASELESS, 0, NULL);
- if(regex) {
- r = g_regex_match (regex, str, 0, NULL);
- g_regex_unref (regex);
- }
-#else
- gsize maxsize;
- gint i;
-
- maxsize = s > strlen(pattern) ? strlen(pattern) : s;
-
- for(i=0; i<strlen(str)&&strlen(&str[i]) >= maxsize;i++)
- if(!g_ascii_strncasecmp (&str[i], pattern, maxsize)) {
- r = TRUE;
- break;
- }
-#endif
-
- return r;
-}
-
-
-static gboolean comp_dockapp_with_filterlist(const gchar *name)
-{
- gchar **patterns = NULL;
- gint i=0;
- gsize s=0;
- gboolean r = FALSE;
-
- if(!wmdock->filterList) return FALSE;
-
- patterns = g_strsplit (wmdock->filterList, ";", 0);
- if(!patterns) return FALSE;
- while(patterns[i]) {
- s = strlen(patterns[i]) > 256 ? 256 : strlen(patterns[i]);
- if(s > 0 &&
- (r=comp_str_with_pattern(name, patterns[i], s)) == TRUE)
- break;
- i++;
- }
-
- g_strfreev(patterns);
- return r;
-}
-
-
-static gboolean has_dockapp_hint(WnckWindow *w)
-{
- Atom atype;
- int afmt;
- unsigned long int nitems;
- unsigned long int naft;
- gboolean r = FALSE;
- unsigned char *dat = NULL;
-
-
- gdk_error_trap_push();
- if (XGetWindowProperty(
- GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
- wnck_window_get_xid(w), XfceDockAppAtom, 0, 1, False,
- XA_CARDINAL, &atype, &afmt, &nitems, &naft, &dat) == Success) {
- if (nitems==1 && ((long int *) dat)[0]==1) {
- r = TRUE;
- }
- XFree(dat);
- }
- XSync(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),False);
-
- gdk_error_trap_pop();
-
- return (r);
-}
-
-
-static void set_xsmp_support(WnckWindow *w)
-{
- /* Workaround to skip the XFCE4 session manager. If the window
- * has this X text property set, the XFCE4 session manager will not
- * automaticly start the dockapp after startup twice. */
-
- XTextProperty tp;
- static Atom _XA_SM_CLIENT_ID = None;
-
- _XA_SM_CLIENT_ID = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "SM_CLIENT_ID", False);
-
-
- tp.value = (unsigned char *) strdup("SM_CLIENT_ID");
- tp.encoding = XA_STRING;
- tp.format = 8;
- tp.nitems = 1;
-
- XSetTextProperty(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
- wnck_window_get_xid(w),
- &tp, _XA_SM_CLIENT_ID);
-
- XFree((unsigned char *)tp.value);
-}
-
-
-static GdkPixbuf *get_icon_from_xpm_scaled(const char **xpmData, gint width, gint height)
-{
- GdkPixbuf *gdkPb = NULL;
- GdkPixbuf *gdkPbScaled = NULL;
-
- gdkPb = gdk_pixbuf_new_from_xpm_data (xpmData);
-
- gdkPbScaled = gdk_pixbuf_scale_simple(gdkPb, width, height,
- GDK_INTERP_BILINEAR);
-
- g_object_unref (G_OBJECT (gdkPb));
-
- return(gdkPbScaled);
-}
-
-
-static void drag_begin_handl (GtkWidget *widget, GdkDragContext *context,
- gpointer dapp)
-{
- gdkPbIcon = get_icon_from_xpm_scaled((const char **) xfce4_wmdock_plugin_xpm,
- DEFAULT_DOCKAPP_WIDTH/2,
- DEFAULT_DOCKAPP_HEIGHT/2);
-
- gtk_drag_set_icon_pixbuf (context, gdkPbIcon, 0, 0);
-
- g_object_unref (G_OBJECT(gdkPbIcon));
-}
-
-#if (GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 12)
-static gboolean drag_failed_handl(GtkWidget *widget, GdkDragContext *context,
- GtkDragResult result, gpointer dapp)
-{
- GtkWidget *gtkDlg;
-
- if(result == GTK_DRAG_RESULT_NO_TARGET && dapp) {
- gtkDlg = gtk_message_dialog_new(GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (wmdock->plugin))),
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_QUESTION,
- GTK_BUTTONS_YES_NO,
- _("Do you want remove the dockapp \"%s\"?"),
- ((DockappNode *) dapp)->name);
-
- if(gtk_dialog_run (GTK_DIALOG(gtkDlg)) == GTK_RESPONSE_YES)
- wmdock_destroy_dockapp((DockappNode *) dapp);
-
- gtk_widget_destroy (GTK_WIDGET(gtkDlg));
- }
-#ifdef DEBUG
- fprintf(fp, "Drag failed of dockapp %s\n", ((DockappNode *) dapp)->name);
- fflush(fp);
-#endif
-
- return TRUE;
-}
-#endif
-
-
-static gboolean drag_drop_handl (GtkWidget *widget, GdkDragContext *context,
- gint x, gint y, guint time, gpointer dapp)
-{
- gboolean is_valid_drop_site;
- GdkAtom target_type;
-
- is_valid_drop_site = TRUE;
-
- if (context-> targets)
- {
- target_type = GDK_POINTER_TO_ATOM
- (g_list_nth_data (context-> targets, 0));
-
- gtk_drag_get_data (widget,context, target_type, time);
- }
-
- else
- {
- is_valid_drop_site = FALSE;
- }
-
- return is_valid_drop_site;
-}
-
-
-
-static void drag_data_received_handl (GtkWidget *widget,
- GdkDragContext *context, gint x, gint y,
- GtkSelectionData *selection_data,
- guint target_type, guint time,
- gpointer dapp)
-{
- glong *_idata;
- gboolean dnd_success = FALSE;
- GList *dappsSrc = NULL;
- GList *dappsDst = NULL;
-
- if(target_type == 0) {
- _idata = (glong*) selection_data-> data;
-#ifdef DEBUG
- fprintf(fp, "DnD integer received: %ld\n", *_idata);
- fflush(fp);
-#endif
- dnd_success = TRUE;
-
- if(dapp) {
- dappsSrc = g_list_nth(wmdock->dapps, *_idata);
- dappsDst = g_list_find(wmdock->dapps, (DockappNode *) dapp);
-
- if(dappsSrc->data != dappsDst->data) {
-
-#ifdef DEBUG
- fprintf(fp, "DnD src dockapp name: %s\n",
- ((DockappNode *) dappsSrc->data)->name);
- fprintf(fp, "DnD dst dockapp name: %s\n",
- ((DockappNode *) dapp)->name);
- fflush(fp);
-#endif
-
- dappsDst->data = dappsSrc->data;
- dappsSrc->data = dapp;
-
-#ifdef DEBUG
- fprintf(fp, "DnD src index: %d\n",
- g_list_index (wmdock->dapps, dappsSrc->data));
- fprintf(fp, "DnD dst index: %d\n",
- g_list_index (wmdock->dapps, dappsDst->data));
- fflush(fp);
-#endif
-
- gtk_box_reorder_child(GTK_BOX(wmdock->box),
- GTK_WIDGET(((DockappNode *) dappsSrc->data)->tile),
- g_list_index (wmdock->dapps, dappsSrc->data));
- gtk_box_reorder_child(GTK_BOX(wmdock->box),
- GTK_WIDGET(((DockappNode *) dappsDst->data)->tile),
- g_list_index (wmdock->dapps, dappsDst->data));
-
- g_list_foreach(wmdock->dapps, (GFunc)wmdock_redraw_dockapp, NULL);
- }
- }
-
- }
-
- gtk_drag_finish (context, dnd_success, FALSE, time);
-
-}
-
-
-
-static void drag_data_get_handl (GtkWidget *widget, GdkDragContext *context,
- GtkSelectionData *selection_data,
- guint target_type, guint time,
- gpointer dapp)
-{
- gint index;
-
- if(target_type == 0 && dapp) {
- index = g_list_index (wmdock->dapps, (DockappNode *) dapp);
-
- gtk_selection_data_set (selection_data, selection_data->target,
- sizeof(index) * _BYTE,
- (guchar*) &index, sizeof (index));
-
-#ifdef DEBUG
- fprintf(fp, "DnD Integer sent: %ld\n", index);
- fflush(fp);
-#endif
- }
-}
-
-
-
-static void wmdock_panel_draw_wmdock_icon (gboolean redraw)
-{
- gdkPbIcon = get_icon_from_xpm_scaled((const char **) xfce4_wmdock_plugin_xpm,
- xfce_panel_plugin_get_size (wmdock->plugin) - 2,
- xfce_panel_plugin_get_size (wmdock->plugin) - 2);
- if(redraw == TRUE && wmdockIcon) {
- gtk_image_set_from_pixbuf (GTK_IMAGE(wmdockIcon), gdkPbIcon);
- } else {
- if(wmdockIcon) gtk_widget_destroy(wmdockIcon);
- wmdockIcon = gtk_image_new_from_pixbuf (gdkPbIcon);
-
- gtk_box_pack_start(GTK_BOX(wmdock->box), GTK_WIDGET(wmdockIcon),
- FALSE, FALSE, 0);
- }
- g_object_unref (G_OBJECT (gdkPbIcon));
-
- gtk_widget_show(GTK_WIDGET(wmdockIcon));
-}
-
-
-static void wmdock_panel_draw_properties_button ()
-{
- if(!btnProperties && wmdock->propDispPropButton == TRUE) {
- btnProperties = xfce_create_panel_button();
- gtk_box_pack_start(GTK_BOX(wmdock->panelBox),
- btnProperties, FALSE, FALSE, 0);
- gtk_box_reorder_child(GTK_BOX(wmdock->panelBox), btnProperties, 0);
-
- g_signal_connect (G_OBJECT(btnProperties), "pressed",
- G_CALLBACK (wmdock_properties_dialog_called_from_widget),
- wmdock->plugin);
-
- gtk_widget_show(GTK_WIDGET(btnProperties));
- }
-}
-
-
-static void wmdock_fill_cmbx(DockappNode *dapp, GtkWidget *gtkComboBox)
-{
-
- if(gtkComboBox) {
-#ifdef DEBUG
- fprintf(fp, "wmdock: %s append to list\n", dapp->name);
- fflush(fp);
-#endif
- gtk_combo_box_append_text (GTK_COMBO_BOX(gtkComboBox), dapp->name);
- }
-}
-
-
-static void wmdock_refresh_properties_dialog()
-{
- gint pos = 0;
-
- if(!prop.dlg || !prop.cbx || !prop.txtCmd) return;
-
- /* Cleanup the old list */
- while((pos = gtk_combo_box_get_active (GTK_COMBO_BOX(prop.cbx)))
- != -1) {
- gtk_combo_box_remove_text(GTK_COMBO_BOX(prop.cbx), pos);
- gtk_combo_box_set_active (GTK_COMBO_BOX(prop.cbx), 0);
- }
-
- gtk_combo_box_popdown (GTK_COMBO_BOX(prop.cbx));
- if(g_list_length(wmdock->dapps) > 0) {
- gtk_widget_set_sensitive (prop.txtCmd, TRUE);
-
- g_list_foreach(wmdock->dapps, (GFunc) wmdock_fill_cmbx, prop.cbx);
-
-
- } else {
- gtk_combo_box_append_text (GTK_COMBO_BOX(prop.cbx),
- _("No dockapp is running!"));
-
- gtk_widget_set_state(prop.txtCmd, GTK_STATE_INSENSITIVE);
- gtk_entry_set_text(GTK_ENTRY(prop.txtCmd), "");
-
- gdkPbIcon = gdk_pixbuf_new_from_xpm_data((const char**)
- xfce4_wmdock_plugin_xpm);
-
- gtk_image_set_from_pixbuf (GTK_IMAGE(prop.image), gdkPbIcon);
-
- g_object_unref (G_OBJECT (gdkPbIcon));
- }
-
- gtk_combo_box_set_active(GTK_COMBO_BOX(prop.cbx), 0);
-
- gtk_widget_show (prop.image);
- gtk_widget_show (prop.cbx);
- gtk_widget_show (prop.txtCmd);
-}
-
-
-static void wmdock_setupdnd_dockapp(DockappNode *dapp)
-{
- /* Make the "well label" a DnD destination. */
- gtk_drag_dest_set (GTK_WIDGET(dapp->s), GTK_DEST_DEFAULT_MOTION, targetList,
- nTargets, GDK_ACTION_MOVE);
-
- gtk_drag_source_set (GTK_WIDGET(dapp->s), GDK_BUTTON1_MASK, targetList,
- nTargets, GDK_ACTION_MOVE);
-
- g_signal_connect (dapp->s, "drag-begin",
- G_CALLBACK (drag_begin_handl), dapp);
-
- g_signal_connect (dapp->s, "drag-data-get",
- G_CALLBACK (drag_data_get_handl), dapp);
-
-#if (GTK_MAJOR_VERSION >= 2 && GTK_MINOR_VERSION >= 12)
- g_signal_connect (dapp->s, "drag-failed",
- G_CALLBACK (drag_failed_handl), dapp);
-#endif
-
- g_signal_connect (dapp->s, "drag-data-received",
- G_CALLBACK(drag_data_received_handl), dapp);
- g_signal_connect (dapp->s, "drag-drop",
- G_CALLBACK (drag_drop_handl), dapp);
-
-
-
-#ifdef DEBUG
- fprintf(fp, "Setup DnD for dockapp %s\n", dapp->name);
- fflush(fp);
-#endif
-}
-
-
-static void wmdock_destroy_dockapp(DockappNode *dapp)
-{
-#ifdef DEBUG
- fprintf(fp, "Destroy dockapp %s\n", dapp->name);
- fflush(fp);
-#endif
- XDestroyWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), dapp->i);
-}
-
-
-static void wmdock_redraw_dockapp(DockappNode *dapp)
-{
- gtk_widget_unmap (GTK_WIDGET(dapp->s));
-
- /* Tile in the background */
- if(wmdock->propDispTile == TRUE) {
- gtk_widget_map(dapp->bg);
- gtk_widget_set_app_paintable(GTK_WIDGET(dapp->s), TRUE);
- gdk_window_set_back_pixmap(GTK_WIDGET(dapp->s)->window, gdkPmTile, FALSE);
- if (GTK_WIDGET_FLAGS(GTK_WIDGET(dapp->s)) & GTK_MAPPED)
- gtk_widget_queue_draw(GTK_WIDGET(dapp->s));
- } else {
- gtk_widget_unmap(dapp->bg);
- gdk_window_set_back_pixmap(GTK_WIDGET(dapp->s)->window, NULL, TRUE);
- }
-
-#ifdef DEBUG
- fprintf(fp, "wmdock: Dockapp %s redrawed with tile %d\n", dapp->name,
- wmdock->propDispTile);
- fflush(fp);
-#endif
-
- gtk_widget_map (GTK_WIDGET(dapp->s));
-
- gtk_widget_show(GTK_WIDGET(dapp->s));
-}
-
-
-static DockappNode *wmdock_find_startup_dockapp(const gchar *compCmd)
-{
- GList *dapps;
- DockappNode *dapp = NULL;
-
- dapps = wmdock->dapps;
-
- while(dapps) {
- dapp = (DockappNode *) dapps->data;
-
- if(dapp) {
- if(!dapp->name && dapp->cmd) {
- if(!g_ascii_strcasecmp(dapp->cmd, compCmd)) {
-#ifdef DEBUG
- fprintf(fp, "found startup dockapp with cmd %s\n", compCmd);
- fflush(fp);
-#endif
- return(dapp);
- }
- }
- }
-
- dapps = g_list_next(dapps);
- }
-
- return(NULL);
-}
-
-
-static void wmdock_dapp_closed(GtkSocket *socket, DockappNode *dapp)
-{
-#ifdef DEBUG
- fprintf(fp, "wmdock: closed window signal ! (window: %s)\n", dapp->name);
- fflush(fp);
-#endif
-
- wmdock->dapps = g_list_remove_all(wmdock->dapps, dapp);
-
- gtk_widget_destroy(GTK_WIDGET(dapp->tile));
- g_free(dapp->name);
- g_free(dapp->cmd);
- g_free(dapp);
-
- if(g_list_length (wmdock->dapps) == 0) {
- wmdock_panel_draw_wmdock_icon(FALSE);
- }
-
- wmdock_refresh_properties_dialog();
-}
-
-
-static gchar *wmdock_get_dockapp_cmd(WnckWindow *w)
-{
- gchar *cmd = NULL;
- int wpid = 0;
- int argc = 0;
- int fcnt, i;
- char **argv;
- FILE *procfp = NULL;
- char buf[BUF_MAX];
-
- XGetCommand(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
- wnck_window_get_xid(w), &argv, &argc);
- if(argc > 0) {
- argv = (char **) realloc(argv, sizeof(char *) * (argc + 1));
- argv[argc] = NULL;
- cmd = g_strjoinv (" ", argv);
- XFreeStringList(argv);
- } else {
- /* Try to get the command line from the proc fs. */
- wpid = wnck_window_get_pid (w);
-
- if(wpid) {
- sprintf(buf, "/proc/%d/cmdline", wpid);
-
- procfp = fopen(buf, "r");
-
- if(procfp) {
- fcnt = read(fileno(procfp), buf, BUF_MAX);
-
- cmd = g_malloc(fcnt+2);
- if(!cmd) return (NULL);
-
- for(i = 0; i < fcnt; i++) {
- if(buf[i] == 0)
- *(cmd+i) = ' ';
- else
- *(cmd+i) = buf[i];
- }
- *(cmd+(i-1)) = 0;
-
- fclose(procfp);
- }
- }
- }
-
- if(!cmd) {
- /* If nothing helps fallback to the window name. */
- cmd = g_strdup(wnck_window_get_name(w));
- }
-
- return(cmd);
-}
-
-
-static GtkWidget *wmdock_create_tile_from_socket(DockappNode *dapp)
-{
- GtkWidget *align = NULL;
- GtkWidget *tile = NULL;
-
- tile = gtk_fixed_new();
-
- dapp->bg = gtk_image_new_from_pixmap(gdkPmTile, NULL);
- gtk_fixed_put(GTK_FIXED(tile), dapp->bg, 0, 0);
- if(wmdock->propDispTile == TRUE)
- gtk_widget_show(dapp->bg);
-
- align = gtk_alignment_new(0.5, 0.5, 0, 0);
- gtk_widget_set_size_request(GTK_WIDGET(align), DEFAULT_DOCKAPP_WIDTH,
- DEFAULT_DOCKAPP_HEIGHT);
- gtk_container_add(GTK_CONTAINER(align), GTK_WIDGET(dapp->s));
- gtk_fixed_put(GTK_FIXED(tile), align, 0, 0);
-
- gtk_widget_show(align);
-
- return (tile);
-}
-
-
-static void wmdock_window_open(WnckScreen *s, WnckWindow *w)
-{
- int wi, he;
- XWMHints *h;
- XWindowAttributes attr;
- DockappNode *dapp = NULL;
- gchar *cmd = NULL;
- gboolean rcDapp = FALSE;
-
- gdk_error_trap_push();
- gdk_flush();
-
- h = XGetWMHints(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
- wnck_window_get_xid(w));
-
- if(!h) return;
-
- if(h->initial_state == WithdrawnState ||
- h->flags == (WindowGroupHint | StateHint | IconWindowHint)
- || has_dockapp_hint(w)) {
-
-#ifdef DEBUG
- fprintf(fp, "wmdock: new wmapp open\n");
- fflush(fp);
-#endif
-
-
-#ifdef DEBUG
- fprintf(fp, "wmdock: New dockapp %s with xid:%u pid:%u arrived sessid:%s\n",
- wnck_window_get_name(w), wnck_window_get_xid(w),
- wnck_window_get_pid(w), wnck_window_get_session_id(w));
- fflush(fp);
-#endif
-
- cmd = wmdock_get_dockapp_cmd(w);
-
- if(wmdock->propDispAddOnlyWM == TRUE &&
- comp_dockapp_with_filterlist(wnck_window_get_name(w)) == FALSE &&
- ! (wmdock_find_startup_dockapp(cmd))) {
- XFree(h);
- return;
- }
-
- if(!cmd) {
- XFree(h);
- return;
- }
-
-#ifdef DEBUG
- fprintf(fp, "wmdock: found cmd %s for window %s\n",
- cmd, wnck_window_get_name(w));
- fflush(fp);
-#endif
-
- if(rcCmds && (dapp = wmdock_find_startup_dockapp(cmd)))
- rcDapp = TRUE;
-
- if(rcDapp == FALSE) {
-#ifdef DEBUG
- fprintf(fp, "wmdock: Create a new dapp window %s\n",
- wnck_window_get_name(w));
- fflush(fp);
-#endif
- dapp = g_new0(DockappNode, 1);
- dapp->s = GTK_SOCKET(gtk_socket_new());
- }
-
- if(h->initial_state == WithdrawnState && h->icon_window) {
- XUnmapWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
- wnck_window_get_xid(w));
- dapp->i =h->icon_window;
- } else {
- dapp->i = wnck_window_get_xid(w);
- }
-
- if(!XGetWindowAttributes(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
- dapp->i, &attr)) {
- wi = DEFAULT_DOCKAPP_WIDTH;
- he = DEFAULT_DOCKAPP_HEIGHT;
- } else {
- wi = attr.width;
- he = attr.height;
- }
-
- if(wi > DEFAULT_DOCKAPP_WIDTH || he > DEFAULT_DOCKAPP_HEIGHT) {
- /* It seems to be no dockapp, because the width or the height of the
- * window a greater than 64 pixels. */
- XMapWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
- wnck_window_get_xid(w));
- gtk_widget_destroy(GTK_WIDGET(dapp->s));
- g_free(cmd);
- g_free(dapp);
- XFree(h);
- return;
- }
-
-#ifdef DEBUG
- fprintf(fp, "wmdock: New dockapp %s width: %d height: %d\n",
- wnck_window_get_name(w), wi, he);
- fflush(fp);
-#endif
-
- gtk_widget_set_size_request(GTK_WIDGET(dapp->s), wi, he);
-
- wnck_window_set_skip_tasklist (w, TRUE);
- wnck_window_set_skip_pager (w, TRUE);
-
- /* Set this property to skip the XFCE4 session manager. */
- set_xsmp_support(w);
-
- dapp->name = g_strdup(wnck_window_get_name(w));
- dapp->cmd = cmd;
-
- if(wmdockIcon) {
- gtk_widget_destroy(wmdockIcon);
- wmdockIcon = NULL;
- }
-
- if(rcDapp == FALSE) {
- XUnmapWindow(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), dapp->i);
-
- dapp->tile = wmdock_create_tile_from_socket(dapp);
-
- gtk_box_pack_start(GTK_BOX(wmdock->box), dapp->tile, FALSE, FALSE, 0);
- }
-
- gtk_socket_add_id(dapp->s, dapp->i);
-
- /* Tile in the background */
- if(wmdock->propDispTile == TRUE) {
- gtk_widget_set_app_paintable(GTK_WIDGET(dapp->s), TRUE);
- gdk_window_set_back_pixmap(GTK_WIDGET(dapp->s)->window, gdkPmTile, FALSE);
- if (GTK_WIDGET_FLAGS(GTK_WIDGET(dapp->s)) & GTK_MAPPED)
- gtk_widget_queue_draw(GTK_WIDGET(dapp->s));
- }
-
- gtk_widget_show_all(GTK_WIDGET(dapp->tile));
-
- g_signal_connect(dapp->s, "plug-removed", G_CALLBACK(wmdock_dapp_closed),
- dapp);
-
- if(rcDapp == FALSE)
- wmdock->dapps=g_list_append(wmdock->dapps, dapp);
-
- /* Test DnD */
- g_list_foreach(wmdock->dapps, (GFunc)wmdock_setupdnd_dockapp, NULL);
-
- wmdock_refresh_properties_dialog();
- }
-
- XFree(h);
-}
+GtkWidget *wmdockIcon = NULL;
+DockappNode *dappProperties = NULL;
+GdkPixbuf *gdkPbTileDefault = NULL;
+GdkPixbuf *gdkPbIcon = NULL;
+WmdockPlugin *wmdock = NULL;
+gchar **rcCmds = NULL;
+gint rcCmdcnt = 0;
+/* TODO: Set panel off to FALSE. */
+gboolean rcPanelOff = TRUE;
static void wmdock_orientation_changed (XfcePanelPlugin *plugin, GtkOrientation orientation, gpointer user_data)
{
- xfce_hvbox_set_orientation ((XfceHVBox *) wmdock->panelBox, orientation);
- xfce_hvbox_set_orientation ((XfceHVBox *) wmdock->box, orientation);
- gtk_widget_show(GTK_WIDGET(wmdock->panelBox));
- gtk_widget_show(GTK_WIDGET(wmdock->box));
+ xfce_hvbox_set_orientation ((XfceHVBox *) wmdock->panelBox, orientation);
+ xfce_hvbox_set_orientation ((XfceHVBox *) wmdock->box, orientation);
+ gtk_widget_show(GTK_WIDGET(wmdock->panelBox));
+ gtk_widget_show(GTK_WIDGET(wmdock->box));
}
static gboolean wmdock_size_changed (XfcePanelPlugin *plugin, int size)
{
- if (xfce_panel_plugin_get_orientation (plugin) ==
- GTK_ORIENTATION_HORIZONTAL) {
- gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
- } else {
- gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
- }
-
- if(wmdockIcon) {
- wmdock_panel_draw_wmdock_icon(TRUE);
- }
-
- return TRUE;
-}
-
-
-static gboolean wmdock_startup_dockapp(const gchar *cmd)
-{
- gboolean ret;
- GError *err = NULL;
+ if (xfce_panel_plugin_get_orientation (plugin) ==
+ GTK_ORIENTATION_HORIZONTAL) {
+ gtk_widget_set_size_request (GTK_WIDGET (plugin), -1, size);
+ } else {
+ gtk_widget_set_size_request (GTK_WIDGET (plugin), size, -1);
+ }
- ret = xfce_exec(cmd, FALSE, FALSE, &err);
+ if(wmdockIcon) {
+ wmdock_panel_draw_wmdock_icon(TRUE);
+ }
- /* Errors will be evaluate in a later version. */
- if(err) g_clear_error (&err);
-
- return(ret);
-}
-
-
-static void wmdock_error_dialog_response (GtkWidget *gtkDlg, gint response)
-{
- gtk_widget_destroy (gtkDlg);
-}
-
-
-static void wmdock_read_rc_file (XfcePanelPlugin *plugin)
-{
- gchar *file = NULL;
- XfceRc *rc = NULL;
- gint i;
- GtkWidget *gtkDlg;
- DockappNode *dapp = NULL;
-
- if (!(file = xfce_panel_plugin_lookup_rc_file (plugin))) return;
-
- rc = xfce_rc_simple_open (file, TRUE);
- g_free(file);
-
- if(!rc) return;
-
- rcCmds = xfce_rc_read_list_entry(rc, "cmds", ";");
- rcCmdcnt = xfce_rc_read_int_entry(rc, "cmdcnt", 0);
- wmdock->propDispTile = xfce_rc_read_bool_entry (rc, "disptile", TRUE);
- wmdock->propDispPropButton = xfce_rc_read_bool_entry (rc, "disppropbtn", FALSE);
- wmdock->propDispAddOnlyWM = xfce_rc_read_bool_entry (rc, "dispaddonlywm", TRUE);
- if(wmdock->filterList) g_free(wmdock->filterList);
- wmdock->filterList = g_strdup(xfce_rc_read_entry (rc, "dafilter", DOCKAPP_FILTER_PATTERN));
-
- if(G_LIKELY(rcCmds != NULL)) {
- for (i = 0; i <= rcCmdcnt; i++) {
-
-#ifdef DEBUG
- fprintf(fp, "wmdock: config will start: %s\n", rcCmds[i]);
- fflush(fp);
-#endif
-
- if(!rcCmds[i]) continue;
- if(wmdock_startup_dockapp(rcCmds[i]) != TRUE) {
- gtkDlg = gtk_message_dialog_new(GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("Failed to start %s!"),
- rcCmds[i]);
- g_signal_connect (gtkDlg, "response", G_CALLBACK (wmdock_error_dialog_response), NULL);
- gtk_widget_show_all (gtkDlg);
- } else {
- /* Create some dummy widget entries to locate the right position on
- window swallow up. */
-
- dapp = g_new0(DockappNode, 1);
- dapp->name = NULL;
- dapp->cmd = rcCmds[i];
-
- dapp->s = GTK_SOCKET(gtk_socket_new());
- dapp->tile = wmdock_create_tile_from_socket(dapp);
-
- gtk_box_pack_start(GTK_BOX(wmdock->box), GTK_WIDGET(dapp->tile),
- FALSE, FALSE, 0);
-
- wmdock->dapps=g_list_append(wmdock->dapps, dapp);
- }
-
- /* Sleep for n microseconds to startup dockapps in the right order. */
- /* g_usleep(250000); */
- }
- }
-
- xfce_rc_close (rc);
+ return TRUE;
}
static void wmdock_free_data(XfcePanelPlugin *plugin)
{
-#ifdef DEBUG
- fprintf(fp, "Called wmdock_free_data\n");
- fflush(fp);
-#endif
-
- g_list_foreach(wmdock->dapps, (GFunc)wmdock_destroy_dockapp, NULL);
-
- gtk_widget_destroy(GTK_WIDGET(wmdockIcon));
- gtk_widget_destroy(GTK_WIDGET(wmdock->box));
- gtk_widget_destroy(GTK_WIDGET(wmdock->panelBox));
- gtk_widget_destroy(GTK_WIDGET(wmdock->align));
- gtk_widget_destroy(GTK_WIDGET(wmdock->eventBox));
- g_list_free(wmdock->dapps);
- g_free(wmdock);
-
-#ifdef DEBUG
- fclose(fp);
-#endif
-}
-
-
-static void wmdock_write_rc_file (XfcePanelPlugin *plugin)
-{
- gchar *file;
- XfceRc *rc;
- gchar **cmds;
- DockappNode *dapp = NULL;
- gint i;
-
- if (!(file = xfce_panel_plugin_save_location (plugin, TRUE))) return;
-
- rc = xfce_rc_simple_open (file, FALSE);
- g_free (file);
-
- if (!rc) return;
-
- if(g_list_length (wmdock->dapps) > 0) {
- cmds = g_malloc(sizeof (gchar *) * (g_list_length (wmdock->dapps) + 1));
+ debug("wmdock.c: Called wmdock_free_data");
- for(i = 0; i < g_list_length(wmdock->dapps); i++) {
- dapp = g_list_nth_data(wmdock->dapps, i);
- if(dapp) {
- if(dapp->name && dapp->cmd)
- cmds[i] = g_strdup(dapp->cmd);
- }
- }
- /* Workaround for a xfce bug in xfce_rc_read_list_entry */
- cmds[i] = NULL;
+ g_list_foreach(wmdock->dapps, (GFunc)wmdock_destroy_dockapp, NULL);
- xfce_rc_write_list_entry(rc, "cmds", cmds, ";");
+ /* Cleanup all the dockapps. */
+ g_list_foreach(wmdock->dapps, (GFunc)wmdock_free_dockapp, NULL);
- g_strfreev(cmds);
+ gtk_widget_destroy(GTK_WIDGET(wmdockIcon));
+ gtk_widget_destroy(GTK_WIDGET(wmdock->box));
+ gtk_widget_destroy(GTK_WIDGET(wmdock->panelBox));
+ gtk_widget_destroy(GTK_WIDGET(wmdock->align));
+ gtk_widget_destroy(GTK_WIDGET(wmdock->eventBox));
+ g_list_free(wmdock->dapps);
+ g_free(wmdock);
- xfce_rc_write_int_entry (rc, "cmdcnt", g_list_length (wmdock->dapps));
- xfce_rc_write_bool_entry (rc, "disptile", wmdock->propDispTile);
- xfce_rc_write_bool_entry (rc, "disppropbtn", wmdock->propDispPropButton);
- xfce_rc_write_bool_entry (rc, "dispaddonlywm", wmdock->propDispAddOnlyWM);
- xfce_rc_write_entry(rc, "dafilter", wmdock->filterList);
- }
-
- xfce_rc_close(rc);
-
- /* Cleanup and close all dockapps! */
- /* wmdock_free_data(plugin); */
-}
-
-
-static void wmdock_properties_chkdisptile(GtkToggleButton *gtkChkDispTile, gpointer user_data)
-{
- wmdock->propDispTile = gtk_toggle_button_get_active(gtkChkDispTile);
-
- g_list_foreach(wmdock->dapps, (GFunc)wmdock_redraw_dockapp, NULL);
- gtk_widget_show_all(GTK_WIDGET(wmdock->box));
+ debug("wmdock.c: wmdock_free_data() done.");
}
-static void wmdock_properties_chkpropbtn(GtkToggleButton *gtkChkPropButton, gpointer user_data)
-{
- wmdock->propDispPropButton = gtk_toggle_button_get_active(gtkChkPropButton);
-
- if(wmdock->propDispPropButton == FALSE) {
- if(btnProperties) gtk_widget_destroy(btnProperties);
- btnProperties = NULL;
- }
- else
- wmdock_panel_draw_properties_button ();
-}
-
-
-static void wmdock_properties_chkaddonlywm(GtkToggleButton *gtkChkAddOnlyWM, gpointer user_data)
-{
- wmdock->propDispAddOnlyWM = gtk_toggle_button_get_active(gtkChkAddOnlyWM);
- gtk_widget_set_sensitive (GTK_WIDGET (prop.txtPatterns),
- wmdock->propDispAddOnlyWM);
-}
-
-
-static gboolean wmdock_properties_refresh_dapp_icon()
-{
- GdkPixmap *pm = NULL;
- DockappNode *dapp = NULL;
- gboolean ret;
-
- if(prop.dlg && prop.image && prop.cbx) {
- dapp = (DockappNode *) g_list_nth_data(wmdock->dapps,
- gtk_combo_box_get_active(GTK_COMBO_BOX(prop.cbx)));
- if(dapp) {
- pm = gdk_pixmap_foreign_new (dapp->i);
- if(pm) {
- gtk_image_set_from_pixmap (GTK_IMAGE(prop.image), pm, NULL);
- gtk_widget_show(prop.image);
- g_object_unref (G_OBJECT(pm));
- }
- else {
- gtk_image_set_from_pixmap (GTK_IMAGE(prop.image), gdkPmTile, NULL);
- gtk_widget_show(prop.image);
- /* Check if the window is gone. */
- if(!wnck_window_get (dapp->i)) {
- ret = FALSE;
- wmdock_dapp_closed(dapp->s, dapp);
- }
- }
- }
-
- ret = TRUE;
- } else ret = FALSE;
-
-#ifdef DEBUG
- if(ret == FALSE) {
- fprintf(fp, "wmdock: wmdock_properties_refresh_dapp_icon status changed to FALSE\n");
- fflush(fp);
- }
-#endif
-
- return (ret);
-}
-
-
-static void wmdock_properties_changed (GtkWidget *gtkComboBox, GtkWidget *gtkTxtCmd)
-{
- DockappNode *dapp = NULL;
-
-
- dapp = (DockappNode *) g_list_nth_data(wmdock->dapps, gtk_combo_box_get_active(GTK_COMBO_BOX(gtkComboBox)));
- if(dapp) {
-#ifdef DEBUG
- fprintf(fp, "wmdock: changed, %s selected:\n", dapp->name);
- fflush(fp);
-#endif
-
- gtk_entry_set_text(GTK_ENTRY(gtkTxtCmd), dapp->cmd);
-
- wmdock_properties_refresh_dapp_icon();
- }
-}
-
-
-static void wmdock_properties_moveup (GtkWidget *gtkBtnMoveUp, GtkWidget *gtkComboBox)
-{
- DockappNode *dapp = NULL;
- gint pos;
-
- pos = gtk_combo_box_get_active(GTK_COMBO_BOX(gtkComboBox));
-
- if(g_list_length(wmdock->dapps) > 1 && pos > 0) {
- dapp = (DockappNode *) g_list_nth_data(wmdock->dapps, pos);
-
- if(dapp) {
- wmdock->dapps = g_list_remove_all(wmdock->dapps, dapp);
- wmdock->dapps = g_list_insert(wmdock->dapps, dapp, pos - 1);
- gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkComboBox), pos);
- gtk_combo_box_insert_text(GTK_COMBO_BOX(gtkComboBox), pos - 1, dapp->name);
- gtk_combo_box_set_active(GTK_COMBO_BOX(gtkComboBox), pos - 1);
- gtk_box_reorder_child(GTK_BOX(wmdock->box), GTK_WIDGET(dapp->tile), pos - 1);
-
- g_list_foreach(wmdock->dapps, (GFunc)wmdock_redraw_dockapp, NULL);
- }
- }
-}
-
-
-static void wmdock_properties_movedown (GtkWidget *gtkBtnMoveDown, GtkWidget *gtkComboBox)
-{
- DockappNode *dapp = NULL;
- gint pos;
-
- pos = gtk_combo_box_get_active(GTK_COMBO_BOX(gtkComboBox));
-
- if(g_list_length(wmdock->dapps) > 1 && pos < g_list_length(wmdock->dapps) - 1) {
- dapp = (DockappNode *) g_list_nth_data(wmdock->dapps, pos);
-
- if(dapp) {
- wmdock->dapps = g_list_remove_all(wmdock->dapps, dapp);
- wmdock->dapps = g_list_insert(wmdock->dapps, dapp, pos + 1);
- gtk_combo_box_remove_text(GTK_COMBO_BOX(gtkComboBox), pos);
- gtk_combo_box_insert_text(GTK_COMBO_BOX(gtkComboBox), pos + 1, dapp->name);
- gtk_combo_box_set_active(GTK_COMBO_BOX(gtkComboBox), pos + 1);
- gtk_box_reorder_child(GTK_BOX(wmdock->box), GTK_WIDGET(dapp->tile), pos + 1);
-
- g_list_foreach(wmdock->dapps, (GFunc)wmdock_redraw_dockapp, NULL);
- }
- }
-}
-
-
-static void wmdock_properties_savecmd (GtkWidget *gtkTxtCmd, GdkEventKey *event, GtkWidget *gtkComboBox)
-{
- DockappNode *dapp = NULL;
- gint pos;
-
- pos = gtk_combo_box_get_active(GTK_COMBO_BOX(gtkComboBox));
-
- dapp = (DockappNode *) g_list_nth_data(wmdock->dapps, pos);
- if(dapp) {
- g_free(dapp->cmd);
- dapp->cmd = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtkTxtCmd)));
- }
-}
-
-
-static void wmdock_properties_dialog_response (GtkWidget *gtkDlg, gint response)
-{
- DockappNode *dapp = NULL;
- gint pos;
-
- if(!gtkDlg) return;
-
- switch(response) {
- case GTK_RESPONSE_NO: /* Remove dockapp */
- if(g_list_length(wmdock->dapps) > 0 && prop.cbx) {
- pos = gtk_combo_box_get_active(GTK_COMBO_BOX(prop.cbx));
-
- dapp = (DockappNode *) g_list_nth_data(wmdock->dapps, pos);
- if(dapp)
- wmdock_destroy_dockapp(dapp);
- }
- break;
-
- default:
- /* Backup the value of the dockapp filter. */
- if(wmdock->propDispAddOnlyWM) {
- if(wmdock->filterList) g_free(wmdock->filterList);
- wmdock->filterList = g_strdup(gtk_entry_get_text(GTK_ENTRY(prop.txtPatterns)));
- }
-
- xfce_panel_plugin_unblock_menu (wmdock->plugin);
- gtk_widget_destroy (gtkDlg);
-
-#ifdef DEBUG
- fprintf(fp, "wmdock: properties dlg closed\n");
- fflush(fp);
-#endif
-
- prop.dlg = prop.cbx = prop.txtCmd = prop.image = NULL;
- break;
- }
-}
-
-
-static void wmdock_properties_dialog_called_from_widget(GtkWidget *widget, XfcePanelPlugin *plugin)
-{
- wmdock_properties_dialog(plugin);
-}
-
-
-static void wmdock_properties_dialog(XfcePanelPlugin *plugin)
+static WmdockPlugin *wmdock_plugin_new (XfcePanelPlugin* plugin)
{
- if(prop.dlg) return; /* Return if properties dialog is already open. */
-
- xfce_panel_plugin_block_menu (plugin);
-
- /* Create the configure dialog. */
- prop.dlg = xfce_titled_dialog_new_with_buttons (_("WMdock"),
- GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))),
- GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR,
- _("Remove dockapp"), GTK_RESPONSE_NO,
- GTK_STOCK_CLOSE, GTK_RESPONSE_OK,
- NULL);
-
- gtk_window_set_position (GTK_WINDOW (prop.dlg), GTK_WIN_POS_CENTER);
- gtk_window_set_icon_name (GTK_WINDOW (prop.dlg), "xfce4-settings");
-
- g_signal_connect (prop.dlg, "response",
- G_CALLBACK (wmdock_properties_dialog_response),
- NULL);
-
- /* Create the layout containers. */
- prop.hbox = gtk_hbox_new(FALSE, 6);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (prop.dlg)->vbox), prop.hbox, FALSE, FALSE, 0);
- gtk_container_set_border_width (GTK_CONTAINER (prop.hbox), 4);
-
- prop.frmGeneral = gtk_frame_new(_("General settings"));
- prop.frmDetect = gtk_frame_new(_("Dockapp detection"));
- prop.vboxGeneral = gtk_vbox_new(FALSE, 6);
- prop.vboxDetect = gtk_vbox_new(FALSE, 6);
-
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (prop.dlg)->vbox), prop.frmGeneral,
- FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (prop.dlg)->vbox), prop.frmDetect,
- FALSE, FALSE, 0);
- gtk_container_set_border_width (GTK_CONTAINER (prop.vboxGeneral), 4);
- gtk_container_set_border_width (GTK_CONTAINER (prop.vboxDetect), 4);
-
- prop.vbox = gtk_vbox_new(FALSE, 4);
- prop.vbox2 = gtk_vbox_new(FALSE, 4);
- gtk_container_set_border_width (GTK_CONTAINER (prop.vbox), 2);
- gtk_container_set_border_width (GTK_CONTAINER (prop.vbox2), 2);
- gtk_box_pack_start (GTK_BOX (prop.hbox), prop.vbox, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (prop.hbox), prop.vbox2, FALSE, FALSE, 0);
-
+ wmdock = g_new0(WmdockPlugin, 1);
+ wmdock->plugin = plugin;
+ wmdock->dapps = NULL;
+ wmdock->propDispTile = TRUE;
+ wmdock->propDispPropButton = FALSE;
+ wmdock->propDispAddOnlyWM = TRUE;
+ /* TODO: Set panel off to FALSE. */
+ wmdock->propPanelOff = TRUE;
+ wmdock->filterList = g_strdup(DOCKAPP_FILTER_PATTERN);
+ wmdock->anchorPos = -1;
- prop.imageContainer = gtk_alignment_new(0.5, 0.5, 0, 0);
- gtk_widget_set_size_request(GTK_WIDGET(prop.imageContainer),
- DEFAULT_DOCKAPP_WIDTH,
- DEFAULT_DOCKAPP_HEIGHT);
- prop.container = gtk_fixed_new();
+ wmdock->eventBox = gtk_event_box_new ();
+ gtk_widget_show(GTK_WIDGET(wmdock->eventBox));
- gdkPbIcon = gdk_pixbuf_new_from_xpm_data((const char**)
- xfce4_wmdock_plugin_xpm);
+ wmdock->align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
- prop.imageTile = gtk_image_new_from_pixmap(gdkPmTile, NULL);
- prop.image = gtk_image_new_from_pixbuf (gdkPbIcon);
+ gtk_widget_show(GTK_WIDGET(wmdock->align));
- g_object_unref (G_OBJECT (gdkPbIcon));
+ gtk_container_add(GTK_CONTAINER(wmdock->eventBox), GTK_WIDGET(wmdock->align));
- gtk_container_add(GTK_CONTAINER(prop.imageContainer), prop.image);
- gtk_container_add(GTK_CONTAINER(prop.container), prop.imageTile);
- gtk_container_add(GTK_CONTAINER(prop.container), prop.imageContainer);
+ wmdock->panelBox = xfce_hvbox_new(xfce_panel_plugin_get_orientation (plugin), FALSE, 0);
+ gtk_widget_show(GTK_WIDGET(wmdock->panelBox));
+ wmdock->box = xfce_hvbox_new(xfce_panel_plugin_get_orientation (plugin), FALSE, 0);
- gtk_box_pack_start (GTK_BOX(prop.vbox), GTK_WIDGET (prop.container),
- FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(wmdock->panelBox), GTK_WIDGET(wmdock->box),
+ FALSE, FALSE, 0);
- prop.btnMoveUp = xfce_arrow_button_new (GTK_ARROW_UP);
- prop.btnMoveDown = xfce_arrow_button_new (GTK_ARROW_DOWN);
- gtk_box_pack_start (GTK_BOX(prop.vbox), GTK_WIDGET (prop.btnMoveUp), FALSE,
- FALSE, 0);
- gtk_box_pack_start (GTK_BOX(prop.vbox), GTK_WIDGET (prop.btnMoveDown), FALSE,
- FALSE, 0);
+ gtk_widget_show(GTK_WIDGET(wmdock->box));
- prop.lblSel = gtk_label_new (_("Select dockapp to configure:"));
- gtk_misc_set_alignment (GTK_MISC (prop.lblSel), 0, 0);
- gtk_box_pack_start (GTK_BOX(prop.vbox2), prop.lblSel, FALSE, FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (wmdock->align), wmdock->panelBox);
- /* Create the dockapp chooser combobox */
- prop.cbx = gtk_combo_box_new_text();
-
- gtk_box_pack_start (GTK_BOX (prop.vbox2), prop.cbx, FALSE, TRUE, 0);
-
- prop.lblCmd = gtk_label_new (_("Shell command:"));
- gtk_misc_set_alignment (GTK_MISC (prop.lblCmd), 0, 0);
- gtk_box_pack_start (GTK_BOX(prop.vbox2), prop.lblCmd, FALSE, FALSE, 0);
- prop.txtCmd = gtk_entry_new();
- if(g_list_length(wmdock->dapps) > 0) {
- gtk_editable_set_editable(GTK_EDITABLE(prop.txtCmd), TRUE);
- } else {
- gtk_editable_set_editable(GTK_EDITABLE(prop.txtCmd), FALSE);
- }
- gtk_box_pack_start (GTK_BOX(prop.vbox2), prop.txtCmd, FALSE, FALSE, 0);
-
- prop.chkDispTile = gtk_check_button_new_with_label(_("Display tile in the background."));
- prop.chkPropButton = gtk_check_button_new_with_label(_("Display a separate WMdock properties\nbutton in the panel."));
- prop.chkAddOnlyWM = gtk_check_button_new_with_label(_("Add only dockapps which start with\npattern in list. (e.g.: ^wm;^as)"));
- prop.txtPatterns = gtk_entry_new();
- gtk_entry_set_text(GTK_ENTRY(prop.txtPatterns), wmdock->filterList);
- gtk_widget_set_sensitive (GTK_WIDGET (prop.txtPatterns),
- wmdock->propDispAddOnlyWM);
-
- gtk_toggle_button_set_active((GtkToggleButton *) prop.chkDispTile,
- wmdock->propDispTile);
- gtk_toggle_button_set_active((GtkToggleButton *) prop.chkPropButton,
- wmdock->propDispPropButton);
- gtk_toggle_button_set_active((GtkToggleButton *) prop.chkAddOnlyWM,
- wmdock->propDispAddOnlyWM);
-
- gtk_container_add(GTK_CONTAINER(prop.frmGeneral), prop.vboxGeneral);
- gtk_container_add(GTK_CONTAINER(prop.frmDetect), prop.vboxDetect);
- gtk_box_pack_start (GTK_BOX(prop.vboxGeneral), prop.chkDispTile,
- FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX(prop.vboxGeneral), prop.chkPropButton,
- FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX(prop.vboxDetect), prop.chkAddOnlyWM,
- FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX(prop.vboxDetect), prop.txtPatterns,
- FALSE, FALSE, 0);
-
-
- /* Fill the dockapp chooser with entries. */
- wmdock_refresh_properties_dialog();
-
- /* Connect some signals to the dialog widgets */
- g_signal_connect(G_OBJECT(prop.cbx), "changed",
- G_CALLBACK(wmdock_properties_changed), prop.txtCmd);
- g_signal_connect(G_OBJECT(prop.txtCmd), "key-release-event",
- G_CALLBACK(wmdock_properties_savecmd), prop.cbx);
- g_signal_connect(G_OBJECT(prop.btnMoveUp), "pressed",
- G_CALLBACK(wmdock_properties_moveup), prop.cbx);
- g_signal_connect(G_OBJECT(prop.btnMoveDown), "pressed",
- G_CALLBACK(wmdock_properties_movedown), prop.cbx);
- g_signal_connect(G_OBJECT(prop.chkDispTile), "toggled",
- G_CALLBACK(wmdock_properties_chkdisptile), NULL);
- g_signal_connect(G_OBJECT(prop.chkPropButton), "toggled",
- G_CALLBACK(wmdock_properties_chkpropbtn), NULL);
- g_signal_connect(G_OBJECT(prop.chkAddOnlyWM), "toggled",
- G_CALLBACK(wmdock_properties_chkaddonlywm), NULL);
-
- g_timeout_add (500, wmdock_properties_refresh_dapp_icon, NULL);
-
- if(g_list_length(wmdock->dapps) > 0)
- wmdock_properties_changed(prop.cbx, prop.txtCmd);
-
- gtk_widget_show_all (prop.dlg);
+ return wmdock;
}
-static WmdockPlugin *wmdock_plugin_new (XfcePanelPlugin* plugin)
+static void wmdock_construct (XfcePanelPlugin *plugin)
{
- wmdock = g_new0(WmdockPlugin, 1);
- wmdock->plugin = plugin;
- wmdock->dapps = NULL;
- wmdock->propDispTile = TRUE;
- wmdock->propDispPropButton = FALSE;
- wmdock->propDispAddOnlyWM = TRUE;
- wmdock->filterList = g_strdup(DOCKAPP_FILTER_PATTERN);
-
- memset(&prop, 0, sizeof(prop));
-
- wmdock->eventBox = gtk_event_box_new ();
- gtk_widget_show(GTK_WIDGET(wmdock->eventBox));
-
- wmdock->align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
-
- gtk_widget_show(GTK_WIDGET(wmdock->align));
+ WnckScreen *s;
- gtk_container_add(GTK_CONTAINER(wmdock->eventBox), GTK_WIDGET(wmdock->align));
+ init_debug();
- wmdock->panelBox = xfce_hvbox_new(xfce_panel_plugin_get_orientation (plugin), FALSE, 0);
- gtk_widget_show(GTK_WIDGET(wmdock->panelBox));
+ s = wnck_screen_get(0);
- wmdock->box = xfce_hvbox_new(xfce_panel_plugin_get_orientation (plugin), FALSE, 0);
+ xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
- gtk_box_pack_start(GTK_BOX(wmdock->panelBox), GTK_WIDGET(wmdock->box),
- FALSE, FALSE, 0);
+ XfceDockAppAtom=XInternAtom(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
+ "_XFCE4_DOCKAPP",False);
- gtk_widget_show(GTK_WIDGET(wmdock->box));
+ wmdock = wmdock_plugin_new (plugin);
- gtk_container_add (GTK_CONTAINER (wmdock->align), wmdock->panelBox);
-
- return wmdock;
-}
-
-
-static void wmdock_construct (XfcePanelPlugin *plugin)
-{
- WnckScreen *s;
+ g_signal_connect(s, "window_opened", G_CALLBACK(wmdock_window_open), NULL);
+ g_signal_connect (plugin, "size-changed", G_CALLBACK (wmdock_size_changed), NULL);
+ g_signal_connect (plugin, "orientation-changed", G_CALLBACK (wmdock_orientation_changed), NULL);
+ g_signal_connect (plugin, "free-data", G_CALLBACK (wmdock_free_data), NULL);
-#ifdef DEBUG
- char debugFile[BUF_MAX];
- sprintf(debugFile, "%s/wmdock-debug.%d", g_get_tmp_dir(), getpid());
- fp = fopen(debugFile, "w");
- if(!fp) fp = stderr;
-#endif
+ gtk_container_add (GTK_CONTAINER (plugin), wmdock->eventBox);
- s = wnck_screen_get(0);
+ xfce_panel_plugin_add_action_widget (plugin, wmdock->eventBox);
- xfce_textdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+ /* Setup the tile image */
+ gdkPbTileDefault = gdk_pixbuf_new_from_xpm_data((const char **) tile_xpm);
- XfceDockAppAtom=XInternAtom(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()),
- "_XFCE4_DOCKAPP",False);
-
- wmdock = wmdock_plugin_new (plugin);
-
- g_signal_connect(s, "window_opened", G_CALLBACK(wmdock_window_open), NULL);
- g_signal_connect (plugin, "size-changed", G_CALLBACK (wmdock_size_changed), NULL);
- g_signal_connect (plugin, "orientation-changed", G_CALLBACK (wmdock_orientation_changed), NULL);
- g_signal_connect (plugin, "free-data", G_CALLBACK (wmdock_free_data), NULL);
+ wmdock_panel_draw_wmdock_icon(FALSE);
- gtk_container_add (GTK_CONTAINER (plugin), wmdock->eventBox);
-
- xfce_panel_plugin_add_action_widget (plugin, wmdock->eventBox);
+ /* Configure plugin dialog */
+ xfce_panel_plugin_menu_show_configure (plugin);
+ g_signal_connect (plugin, "configure-plugin",
+ G_CALLBACK (wmdock_properties_dialog), NULL);
- /* Setup the tile image */
- gdkPmTile = gdk_pixmap_create_from_xpm_d (wmdock->eventBox->window, NULL,
- NULL, tile_xpm);
+ /* Read the config file and start the dockapps */
+ wmdock_read_rc_file(plugin);
- wmdock_panel_draw_wmdock_icon(FALSE);
-
- /* Configure plugin dialog */
- xfce_panel_plugin_menu_show_configure (plugin);
- g_signal_connect (plugin, "configure-plugin",
- G_CALLBACK (wmdock_properties_dialog), NULL);
-
- /* Read the config file and start the dockapps */
- wmdock_read_rc_file(plugin);
+ wmdock_panel_draw_properties_button();
- wmdock_panel_draw_properties_button();
-
- g_signal_connect (plugin, "save", G_CALLBACK (wmdock_write_rc_file), NULL);
+ g_signal_connect (plugin, "save", G_CALLBACK (wmdock_write_rc_file), NULL);
}
XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (wmdock_construct);
diff --git a/panel-plugin/wmdock.h b/panel-plugin/wmdock.h
index f8c42c9..4021dcc 100644
--- a/panel-plugin/wmdock.h
+++ b/panel-plugin/wmdock.h
@@ -1,6 +1,6 @@
/* wmdock xfce4 plugin by Andre Ellguth
*
- * $Id$
+ * $Id: wmdock.h 18 2012-08-06 21:00:29Z ellguth $
*
* Authors:
* Andre Ellguth <ellguth at ibh.de>
@@ -30,31 +30,32 @@
#define WNCK_I_KNOW_THIS_IS_UNSTABLE
#include <libwnck/libwnck.h>
-typedef struct _dockapp {
- GtkSocket *s;
- GdkNativeWindow i;
- GtkWidget *bg;
- GtkWidget *tile;
- gchar *name;
- gchar *cmd;
-} DockappNode;
-
typedef struct {
- XfcePanelPlugin *plugin;
+ XfcePanelPlugin *plugin;
- GtkWidget *eventBox;
+ GtkWidget *eventBox;
/* Plugin specific definitions */
- GtkWidget *align;
- GtkWidget *box;
- GtkWidget *panelBox;
+ GtkWidget *align;
+ GtkWidget *box;
+ GtkWidget *panelBox;
- gboolean propDispTile;
- gboolean propDispPropButton;
- gboolean propDispAddOnlyWM;
- gchar *filterList;
-
- GList *dapps;
+ gboolean propDispTile;
+ gboolean propDispPropButton;
+ gboolean propDispAddOnlyWM;
+ gboolean propPanelOff;
+ gint anchorPos;
+ gchar *filterList;
+
+ GList *dapps;
} WmdockPlugin;
+#define BUF_MAX 4096
+#define DEFAULT_DOCKAPP_WIDTH 64
+#define DEFAULT_DOCKAPP_HEIGHT 64
+/* Default filter for dockapps. All dockapps starting with "wm" or "as". */
+#define DOCKAPP_FILTER_PATTERN "^wm;^as"
+
+#define IS_PANELOFF(__wmdock) (__wmdock->propPanelOff == TRUE)
+
#endif /* __WMDOCK_H__ */
More information about the Xfce4-commits
mailing list