Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intergration with xmonad #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions xmonadLog/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
add_subdirectory(src)
add_subdirectory(data)
8 changes: 8 additions & 0 deletions xmonadLog/data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

########### install files ###############

install (FILES ${CMAKE_CURRENT_BINARY_DIR}/xmonadLog.conf
preview.jpg
icon.png
DESTINATION ${xmonadlogdatadir})

Binary file added xmonadLog/data/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added xmonadLog/data/preview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions xmonadLog/data/xmonadLog.conf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#@VERSION_XMONADLOG@

#[gtk-about]
[Icon]

#F[Icon]
frame_maininfo=

#d Name of the dock it belongs to:
dock name =

#s[Default] Name of the icon as it will appear in its caption in the dock:
name =
#v
sep_display=


#j[0;2560] Desired icon size for this applet
#{Set to 0 to use the default applet size}
icon size = 0;0

order=

#A
handbook=xmonadLog



#[gtk-preferences]
[Configuration]


#i[-128;128] text dx :
text dx = 0

#i[-128;128] text dy :
text dy = 0

38 changes: 38 additions & 0 deletions xmonadLog/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

########### sources ###############

SET(MODULE_SRCS
applet-struct.h
applet-init.c applet-init.h
applet-config.c applet-config.h
applet-notifications.c applet-notifications.h
)

add_library(${PACKAGE_XMONADLOG} SHARED ${MODULE_SRCS})

########### compil ###############
add_definitions (-DMY_APPLET_SHARE_DATA_DIR="${xmonadlogdatadir}")
add_definitions (-DMY_APPLET_PREVIEW_FILE="preview.jpg")
add_definitions (-DMY_APPLET_CONF_FILE="xmonadLog.conf")
add_definitions (-DMY_APPLET_USER_DATA_DIR="xmonadLog")
add_definitions (-DMY_APPLET_VERSION="${VERSION_XMONADLOG}")
add_definitions (-DMY_APPLET_GETTEXT_DOMAIN="${GETTEXT_XMONADLOG}")
add_definitions (-DMY_APPLET_DOCK_VERSION="${dock_version}")
add_definitions (-DMY_APPLET_ICON_FILE="icon.png")
### uncomment the following line to allow multi-instance applet.
#add_definitions (-DCD_APPLET_MULTI_INSTANCE="1")
### uncomment the following line to allow extended OpenGL drawing.
#add_definitions (-DGL_GLEXT_PROTOTYPES="1")

include_directories (
${PACKAGE_INCLUDE_DIRS})

link_directories (
${PACKAGE_LIBRARY_DIRS})

target_link_libraries (${PACKAGE_XMONADLOG}
${PACKAGE_LIBRARIES})

########### install files ###############

install(TARGETS ${PACKAGE_XMONADLOG} DESTINATION ${pluginsdir})
45 changes: 45 additions & 0 deletions xmonadLog/src/applet-config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* This file is a part of the Cairo-Dock project
*
* Copyright : (C) see the 'copyright' file.
* E-mail : see the 'copyright' file.
*
* 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 3
* 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 program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <string.h>
#include <cairo-dock.h>

#include "applet-struct.h"
#include "applet-config.h"


//\_________________ Here you have to get all your parameters from the conf file. Use the macros CD_CONFIG_GET_BOOLEAN, CD_CONFIG_GET_INTEGER, CD_CONFIG_GET_STRING, etc. myConfig has been reseted to 0 at this point. This function is called at the beginning of init and reload.
CD_APPLET_GET_CONFIG_BEGIN
myConfig.iTextDx = CD_CONFIG_GET_INTEGER ("Configuration", "text dx");
myConfig.iTextDy = CD_CONFIG_GET_INTEGER ("Configuration", "text dy");

CD_APPLET_GET_CONFIG_END


//\_________________ Here you have to free all ressources allocated for myConfig. This one will be reseted to 0 at the end of this function. This function is called right before you get the applet's config, and when your applet is stopped, in the end.
CD_APPLET_RESET_CONFIG_BEGIN

CD_APPLET_RESET_CONFIG_END


//\_________________ Here you have to free all ressources allocated for myData. This one will be reseted to 0 at the end of this function. This function is called when your applet is stopped, in the very end.
CD_APPLET_RESET_DATA_BEGIN


CD_APPLET_RESET_DATA_END
30 changes: 30 additions & 0 deletions xmonadLog/src/applet-config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* This file is a part of the Cairo-Dock project
*
* Copyright : (C) see the 'copyright' file.
* E-mail : see the 'copyright' file.
*
* 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 3
* 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 program. If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef __APPLET_CONFIG__
#define __APPLET_CONFIG__

#include <cairo-dock.h>


CD_APPLET_CONFIG_H


#endif
160 changes: 160 additions & 0 deletions xmonadLog/src/applet-init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/**
* This file is a part of the Cairo-Dock project
*
* Copyright : (C) see the 'copyright' file.
* E-mail : see the 'copyright' file.
*
* 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 3
* 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 program. If not, see <http://www.gnu.org/licenses/>.
*/


/* D-Bus related functions come from xmonad-log-applet
*
* Copyright (c) 2009 Adam Wick
* Copyright (c) 2011-2012 Alexander Kojevnikov
* Copyright (c) 2011 Dan Callaghan
* Copyright (c) 2012 Ari Croock
*
*
*/


/* Text rendering comes from
http://x11.gp2x.de/personal/google/

*/


#include "stdlib.h"

#include "applet-config.h"
#include "applet-notifications.h"
#include "applet-struct.h"
#include "applet-init.h"

#include <dbus/dbus-glib.h>


void rendertext(cairo_t *cr,const char* msg) {
PangoLayout *layout; // layout for a paragraph of text
//PangoFontDescription *desc; // this structure stores a description of the style of font you'd most like
cairo_identity_matrix (cr);
cairo_translate(cr,myConfig.iTextDx ,myConfig.iTextDy);
//printf("translating to %d,%d\n",myConfig.iTextDx ,myConfig.iTextDy);
// set the origin of cairo instance 'cr' to (10,20) (i.e. this is where
// drawing will start from).
layout = pango_cairo_create_layout(cr); // init pango layout ready for use
pango_layout_set_markup(layout, msg, -1); // sets the text to be associated with the layout (final arg is length, -1
// to calculate automatically when passing a nul-terminated string)
//desc = pango_font_description_from_string("Sans Bold 8"); // specify the font that would be ideal for your particular use
//pango_layout_set_font_description(layout, desc); // assign the previous font description to the layout
//pango_font_description_free(desc); // free the description

cairo_set_source_rgb(cr, 0.0, 0.0, 1.0); // set the colour to blue
pango_cairo_update_layout(cr, layout); // if the target surface or transformation properties of the cairo instance
// have changed, update the pango layout to reflect this
pango_cairo_show_layout(cr, layout); // draw the pango layout onto the cairo surface

g_object_unref(layout); // free the layout
}





static void signal_handler(DBusGProxy *obj, const char *msg)
{
CD_APPLET_START_DRAWING_MY_ICON_OR_RETURN_CAIRO ();

//printf("received %s\n",msg);
rendertext(myDrawContext,msg);

CD_APPLET_FINISH_DRAWING_MY_ICON_CAIRO;
}



static void set_up_dbus_transfer()
{
DBusGConnection *connection;
DBusGProxy *proxy;
GError *error= NULL;

connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
if(connection == NULL) {
g_printerr("Failed to open connection: %s\n", error->message);
g_error_free(error);
}

proxy = dbus_g_proxy_new_for_name(
connection, "org.xmonad.Log", "/org/xmonad/Log", "org.xmonad.Log");
error = NULL;

dbus_g_proxy_add_signal(proxy, "Update", G_TYPE_STRING, G_TYPE_INVALID);
dbus_g_proxy_connect_signal(proxy, "Update", (GCallback)signal_handler, NULL, NULL);
// printf("should be connected");
}



CD_APPLET_DEFINITION (N_("xmonadLog"),
3, 3, 2,
CAIRO_DOCK_CATEGORY_APPLET_ACCESSORY,
N_("Xmonad D-Bus Log printer\n"
"cairo-dock equivalent of xmonad-log-applet"),
"fabiodl")


//\___________ Here is where you initiate your applet. myConfig is already set at this point, and also myIcon, myContainer, myDock, myDesklet (and myDrawContext if you're in dock mode). The macro CD_APPLET_MY_CONF_FILE and CD_APPLET_MY_KEY_FILE can give you access to the applet's conf-file and its corresponding key-file (also available during reload). If you're in desklet mode, myDrawContext is still NULL, and myIcon's buffers has not been filled, because you may not need them then (idem when reloading).
CD_APPLET_INIT_BEGIN
if (myDesklet)
{
CD_APPLET_SET_DESKLET_RENDERER ("Simple"); // set a desklet renderer.
CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET;
}


/// To be continued ...

set_up_dbus_transfer();

CD_APPLET_REGISTER_FOR_CLICK_EVENT;
CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
CD_APPLET_INIT_END


//\___________ Here is where you stop your applet. myConfig and myData are still valid, but will be reseted to 0 at the end of the function. In the end, your applet will go back to its original state, as if it had never been activated.
CD_APPLET_STOP_BEGIN
CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;

/// To be continued ...


CD_APPLET_STOP_END


//\___________ The reload occurs in 2 occasions : when the user changes the applet's config, and when the user reload the cairo-dock's config or modify the desklet's size. The macro CD_APPLET_MY_CONFIG_CHANGED can tell you this. myConfig has already been reloaded at this point if you're in the first case, myData is untouched. You also have the macro CD_APPLET_MY_CONTAINER_TYPE_CHANGED that can tell you if you switched from dock/desklet to desklet/dock mode.
CD_APPLET_RELOAD_BEGIN
if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED) // we are now in a desklet, set a renderer.
{
CD_APPLET_SET_DESKLET_RENDERER ("Simple");
}

if (CD_APPLET_MY_CONFIG_CHANGED)
{

/// To be continued ...

}
CD_APPLET_RELOAD_END
31 changes: 31 additions & 0 deletions xmonadLog/src/applet-init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* This file is a part of the Cairo-Dock project
*
* Copyright : (C) see the 'copyright' file.
* E-mail : see the 'copyright' file.
*
* 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 3
* 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 program. If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef __APPLET_INIT__
#define __APPLET_INIT__


#include <cairo-dock.h>


CD_APPLET_H


#endif
Loading