1 /*
2  * Gromit -- a program for painting on the screen
3  * Copyright (C) 2000 Simon Budig <Simon.Budig@unix-ag.org>
4  *
5  * MPX modifications Copyright (C) 2009 Christian Beier <dontmind@freeshell.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  *
21  */
22 
23 #ifndef GROMIT_MPX_H
24 #define GROMIT_MPX_H
25 
26 #include "build-config.h"
27 
28 #include <glib.h>
29 #include <gdk/gdk.h>
30 #include <gtk/gtk.h>
31 #ifdef APPINDICATOR_IS_LEGACY
32 #include <libappindicator/app-indicator.h>
33 #else
34 #include <libayatana-appindicator/app-indicator.h>
35 #endif
36 
37 #define GROMIT_MOUSE_EVENTS ( GDK_BUTTON_MOTION_MASK | \
38                               GDK_BUTTON_PRESS_MASK | \
39                               GDK_BUTTON_RELEASE_MASK )
40 
41 #define GROMIT_WINDOW_EVENTS ( GROMIT_MOUSE_EVENTS | GDK_EXPOSURE_MASK)
42 
43 /* Atoms used to control Gromit */
44 #define GA_CONTROL    gdk_atom_intern ("Gromit/control", FALSE)
45 #define GA_STATUS     gdk_atom_intern ("Gromit/status", FALSE)
46 #define GA_QUIT       gdk_atom_intern ("Gromit/quit", FALSE)
47 #define GA_ACTIVATE   gdk_atom_intern ("Gromit/activate", FALSE)
48 #define GA_DEACTIVATE gdk_atom_intern ("Gromit/deactivate", FALSE)
49 #define GA_TOGGLE     gdk_atom_intern ("Gromit/toggle", FALSE)
50 #define GA_VISIBILITY gdk_atom_intern ("Gromit/visibility", FALSE)
51 #define GA_CLEAR      gdk_atom_intern ("Gromit/clear", FALSE)
52 #define GA_RELOAD     gdk_atom_intern ("Gromit/reload", FALSE)
53 #define GA_UNDO       gdk_atom_intern ("Gromit/undo", FALSE)
54 #define GA_REDO       gdk_atom_intern ("Gromit/redo", FALSE)
55 
56 #define GA_DATA       gdk_atom_intern ("Gromit/data", FALSE)
57 #define GA_TOGGLEDATA gdk_atom_intern ("Gromit/toggledata", FALSE)
58 
59 #define GROMIT_MAX_UNDO 4
60 
61 typedef enum
62 {
63   GROMIT_PEN,
64   GROMIT_ERASER,
65   GROMIT_RECOLOR
66 } GromitPaintType;
67 
68 typedef struct
69 {
70   GromitPaintType type;
71   guint           width;
72   gfloat          arrowsize;
73   guint           minwidth;
74   GdkRGBA         *paint_color;
75   cairo_t         *paint_ctx;
76   gdouble         pressure;
77 } GromitPaintContext;
78 
79 typedef struct
80 {
81   gint x;
82   gint y;
83   gint width;
84 } GromitStrokeCoordinate;
85 
86 typedef struct
87 {
88   gdouble      lastx;
89   gdouble      lasty;
90   guint32      motion_time;
91   GList*       coordlist;
92   GdkDevice*   device;
93   guint        index;
94   guint        state;
95   GromitPaintContext *cur_context;
96   gboolean     is_grabbed;
97   gboolean     was_grabbed;
98   GdkDevice*   lastslave;
99 } GromitDeviceData;
100 
101 
102 typedef struct
103 {
104   GtkWidget   *win;
105   AppIndicator *trayicon;
106 
107   GdkCursor   *paint_cursor;
108   GdkCursor   *erase_cursor;
109 
110   GdkDisplay  *display;
111   GdkScreen   *screen;
112   gboolean     xinerama;
113   gboolean     composited;
114   GdkWindow   *root;
115   gchar       *hot_keyval;
116   guint        hot_keycode;
117   gchar       *undo_keyval;
118   guint        undo_keycode;
119   gdouble      opacity;
120 
121   GdkRGBA     *white;
122   GdkRGBA     *black;
123   GdkRGBA     *red;
124 
125   GromitPaintContext *default_pen;
126   GromitPaintContext *default_eraser;
127 
128   GHashTable  *tool_config;
129 
130   cairo_surface_t *backbuffer;
131 
132   GHashTable  *devdatatable;
133 
134   guint        timeout_id;
135   guint        modified;
136   guint        delayed;
137   guint        maxwidth;
138   guint        width;
139   guint        height;
140   guint        client;
141   guint        painted;
142   gboolean     hidden;
143   gboolean     debug;
144 
145   gchar       *clientdata;
146 
147   cairo_surface_t *undobuffer[GROMIT_MAX_UNDO];
148   gint            undo_head, undo_depth, redo_depth;
149 
150   gboolean show_intro_on_startup;
151 
152 } GromitData;
153 
154 
155 void toggle_visibility (GromitData *data);
156 void hide_window (GromitData *data);
157 void show_window (GromitData *data);
158 
159 void parse_print_help (gpointer key, gpointer value, gpointer user_data);
160 
161 void select_tool (GromitData *data, GdkDevice *device, GdkDevice *slave_device, guint state);
162 
163 void copy_surface (cairo_surface_t *dst, cairo_surface_t *src);
164 void swap_surfaces (cairo_surface_t *a, cairo_surface_t *b);
165 void snap_undo_state (GromitData *data);
166 void undo_drawing (GromitData *data);
167 void redo_drawing (GromitData *data);
168 
169 void draw_line (GromitData *data, GdkDevice *dev, gint x1, gint y1, gint x2, gint y2);
170 void draw_arrow (GromitData *data, GdkDevice *dev, gint x1, gint y1, gint width, gfloat direction);
171 void clear_screen (GromitData *data);
172 
173 gboolean coord_list_get_arrow_param (GromitData *data,
174 					    GdkDevice  *dev,
175 					    gint        search_radius,
176 					    gint       *ret_width,
177 					    gfloat     *ret_direction);
178 void coord_list_prepend (GromitData *data, GdkDevice* dev, gint x, gint y, gint width);
179 void coord_list_free (GromitData *data, GdkDevice* dev);
180 
181 
182 GromitPaintContext *paint_context_new (GromitData *data, GromitPaintType type,
183 				       GdkRGBA *fg_color, guint width, guint arrowsize,
184                                        guint minwidth);
185 void paint_context_free (GromitPaintContext *context);
186 
187 void indicate_active(GromitData *data, gboolean YESNO);
188 
189 #endif
190