summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@redhat.com>2006-07-08 16:18:59 -0400
committerKristian Høgsberg <krh@redhat.com>2006-07-08 16:18:59 -0400
commite06b4cc6b24eec039e5902948158394ca0906128 (patch)
treee0fe77a6a5f3d79af96beeae326bdd5327328c75
parentcde68c08fa0a7cc76900f6218eb972a6cbc660a5 (diff)
Make dock placement configurable.
-rw-r--r--akamaru.c4
-rw-r--r--akamaru.h2
-rw-r--r--dock.c196
-rw-r--r--main.c3
4 files changed, 142 insertions, 63 deletions
diff --git a/akamaru.c b/akamaru.c
index 5a9baa0..f8c7cbb 100644
--- a/akamaru.c
+++ b/akamaru.c
@@ -352,8 +352,8 @@ object_accumulate_forces (Object *object, void *data)
Vector v;
/* Gravity */
- object->force.x = 0;
- object->force.y = model->gravity * object->mass;
+ object->force.x = model->gravity.x * object->mass;
+ object->force.y = model->gravity.y * object->mass;
/* Friction */
v.x = object->position.x - object->previous_position.x;
diff --git a/akamaru.h b/akamaru.h
index b1284b1..219bd70 100644
--- a/akamaru.h
+++ b/akamaru.h
@@ -132,7 +132,7 @@ struct _Model {
double k;
double friction;
double elasticity;
- double gravity;
+ Vector gravity;
int constrain_iterations;
double theta;
diff --git a/dock.c b/dock.c
index 5182bc4..2220325 100644
--- a/dock.c
+++ b/dock.c
@@ -20,6 +20,8 @@
#define KIBA_GCONF_PATH "/apps/kiba"
#define PIXMAP_PATH "/usr/share/pixmaps"
+#define ICON_SIZE 48
+
GQuark kiba_error_quark (void)
{
static GQuark q = 0;
@@ -36,23 +38,40 @@ typedef struct _KibaDock KibaDock;
typedef struct _KibaDockClass KibaDockClass;
typedef struct _KibaLauncher KibaLauncher;
+typedef enum {
+ KIBA_DOCK_POSITION_LEFT_SIDE_TOP,
+ KIBA_DOCK_POSITION_LEFT_SIDE_CENTER,
+ KIBA_DOCK_POSITION_LEFT_SIDE_BOTTOM,
+
+ KIBA_DOCK_POSITION_RIGHT_SIDE_TOP,
+ KIBA_DOCK_POSITION_RIGHT_SIDE_CENTER,
+ KIBA_DOCK_POSITION_RIGHT_SIDE_BOTTOM,
+
+ KIBA_DOCK_POSITION_TOP_SIDE_LEFT,
+ KIBA_DOCK_POSITION_TOP_SIDE_CENTER,
+ KIBA_DOCK_POSITION_TOP_SIDE_RIGHT,
+
+ KIBA_DOCK_POSITION_BOTTOM_SIDE_LEFT,
+ KIBA_DOCK_POSITION_BOTTOM_SIDE_CENTER,
+ KIBA_DOCK_POSITION_BOTTOM_SIDE_RIGHT
+} KibaDockPosition;
+
struct _KibaDock
{
- GtkWidget widget;
-
- Model model;
- Anchor *anchor;
- Anchor *mouse_anchor;
-
- int width;
- int height;
- int spacing;
- int num_launchers;
- GList *launchers;
- int drag_offset_x;
- int drag_offset_y;
- int drag_distance;
- KibaLauncher *dragging_launcher;
+ GtkWidget widget;
+
+ KibaDockPosition position;
+ Model model;
+ Anchor *anchor;
+ Anchor *mouse_anchor;
+
+ int spacing;
+ int num_launchers;
+ GList *launchers;
+ int drag_offset_x;
+ int drag_offset_y;
+ int drag_distance;
+ KibaLauncher *dragging_launcher;
GConfClient *gconf_client;
@@ -121,6 +140,27 @@ static gint timeout_callback (gpointer data);
G_DEFINE_TYPE (KibaDock, kiba_dock, GTK_TYPE_WIDGET)
+typedef struct {
+ GtkOrientation orientation;
+ int halignment;
+ int valignment;
+} KibaDockLayoutData;
+
+static const KibaDockLayoutData kiba_dock_layout_data[] = {
+ { GTK_ORIENTATION_VERTICAL, 0, 0 },
+ { GTK_ORIENTATION_VERTICAL, 0, 1 },
+ { GTK_ORIENTATION_VERTICAL, 0, 2 },
+ { GTK_ORIENTATION_VERTICAL, 2, 0 },
+ { GTK_ORIENTATION_VERTICAL, 2, 1 },
+ { GTK_ORIENTATION_VERTICAL, 2, 2 },
+ { GTK_ORIENTATION_HORIZONTAL, 0, 0 },
+ { GTK_ORIENTATION_HORIZONTAL, 1, 0 },
+ { GTK_ORIENTATION_HORIZONTAL, 2, 0 },
+ { GTK_ORIENTATION_HORIZONTAL, 0, 2 },
+ { GTK_ORIENTATION_HORIZONTAL, 1, 2 },
+ { GTK_ORIENTATION_HORIZONTAL, 2, 2 }
+};
+
static void
kiba_dock_class_init (KibaDockClass *class)
{
@@ -173,7 +213,8 @@ kiba_dock_init (KibaDock *dock)
width = gdk_screen_get_width (screen);
height = gdk_screen_get_height (screen);
- dock->spacing = 50;
+ dock->position = KIBA_DOCK_POSITION_BOTTOM_SIDE_CENTER;
+ dock->spacing = ICON_SIZE;
kiba_dock_init_model (dock, width, height);
@@ -228,24 +269,32 @@ kiba_dock_paint (KibaDock *dock)
GtkWidget *widget = GTK_WIDGET (dock);
cairo_pattern_t *gradient;
cairo_t *cr;
- const int hmargin = 5, vmargin = 40, radius = 5;
+ const int margin = 1, radius = 5;
+ int x0, y0, x1, y1;
+ const KibaDockLayoutData *d;
+
+ d = &kiba_dock_layout_data[dock->position];
+ x0 = (d->halignment == 0 ? -radius : margin);
+ y0 = (d->valignment == 0 ? -radius : margin);;
+ x1 = widget->allocation.width - (d->halignment == 2 ? -radius : margin);
+ y1 = widget->allocation.height - (d->valignment == 2 ? -radius : margin);
cr = gdk_cairo_create (widget->window);
cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
cairo_paint (cr);
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
- cairo_move_to (cr, hmargin, dock->height);
- cairo_line_to (cr, hmargin, vmargin + radius);
- cairo_arc (cr, hmargin + radius, vmargin + radius,
- radius, M_PI, 3 * M_PI / 2);
- cairo_line_to (cr, dock->width - hmargin - radius, vmargin);
- cairo_arc (cr, dock->width - hmargin - radius, vmargin + radius,
- radius, 3 * M_PI / 2, 2 * M_PI);
- cairo_line_to (cr, dock->width - hmargin, dock->height);
-
- gradient = cairo_pattern_create_linear (dock->width / 2 - 1, vmargin,
- dock->width / 2 + 1, dock->height);
+ cairo_arc (cr, x0 + radius, y1 - radius, radius, M_PI / 2, M_PI);
+ cairo_line_to (cr, x0, y0 + radius);
+ cairo_arc (cr, x0 + radius, y0 + radius, radius, M_PI, 3 * M_PI / 2);
+ cairo_line_to (cr, x1 - radius, y0);
+ cairo_arc (cr, x1 - radius, y0 + radius, radius, 3 * M_PI / 2, 2 * M_PI);
+ cairo_line_to (cr, x1, y1 - radius);
+ cairo_arc (cr, x1 - radius, y1 - radius, radius, 0, M_PI / 2);
+ cairo_close_path (cr);
+
+ gradient = cairo_pattern_create_linear ((x0 + x1) / 2 - 1, y0,
+ (x0 + x1) / 2 + 1, y1);
cairo_pattern_add_color_stop_rgba (gradient, 0, 1, 1, 1, 0.4);
cairo_pattern_add_color_stop_rgba (gradient, 1, 1, 1, 1, 0.6);
cairo_set_source (cr, gradient);
@@ -336,32 +385,63 @@ kiba_dock_realize (GtkWidget *widget)
}
static void
-kiba_dock_show (GtkWidget *widget)
+kiba_dock_layout (KibaDock *dock)
{
- KibaDock *dock = KIBA_DOCK (widget);
+ const KibaDockLayoutData *d;
GtkAllocation allocation;
GdkScreen *screen;
int width, height;
- const int padding = 20;
+ const int cap_size = 20;
- GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
+ screen = gdk_screen_get_default ();
+ width = gdk_screen_get_width (screen);
+ height = gdk_screen_get_height (screen);
- if (!GTK_WIDGET_REALIZED (widget))
+ d = &kiba_dock_layout_data[dock->position];
+
+ if (d->orientation == GTK_ORIENTATION_VERTICAL)
+ {
+ allocation.width = 2 * ICON_SIZE / 3;
+ allocation.height = dock->num_launchers * dock->spacing +
+ (d->valignment == 0 ? 2 * cap_size : cap_size);
+ }
+ else
+ {
+ allocation.width = dock->num_launchers * dock->spacing +
+ (d->halignment == 0 ? 2 * cap_size : cap_size);
+ allocation.height = 2 * ICON_SIZE / 3;
+ }
+
+ allocation.x = d->halignment * (width - allocation.width) / 2;
+ allocation.y = d->valignment * (height - allocation.height) / 2;
+
+ dock->anchor->x = allocation.x + allocation.width / 2;
+ dock->anchor->y = allocation.y + allocation.height / 2;
+
+ if (d->orientation == GTK_ORIENTATION_VERTICAL)
{
- screen = gdk_screen_get_default ();
- width = gdk_screen_get_width (screen);
- height = gdk_screen_get_height (screen);
+ dock->model.gravity.x = (d->halignment - 1) * 50;
+ dock->model.gravity.y = 0;
+ }
+ else
+ {
+ dock->model.gravity.x = 0;
+ dock->model.gravity.y = (d->valignment - 1) * 50;
+ }
- allocation.width = dock->num_launchers * dock->spacing + 2 * padding;
- allocation.height = dock->spacing + padding;
- allocation.x = (width - allocation.width + dock->spacing) / 2;
- allocation.y = height - allocation.height;
+ gtk_widget_size_allocate (GTK_WIDGET (dock), &allocation);
+}
+
+static void
+kiba_dock_show (GtkWidget *widget)
+{
+ KibaDock *dock = KIBA_DOCK (widget);
- /* Technically, this should be in kiba_dock_size_allocate (). */
- dock->width = allocation.width;
- dock->height = allocation.height;
+ GTK_WIDGET_SET_FLAGS (widget, GTK_VISIBLE);
- gtk_widget_size_allocate (widget, &allocation);
+ if (!GTK_WIDGET_REALIZED (widget))
+ {
+ kiba_dock_layout (dock);
gtk_widget_realize (widget);
}
@@ -395,8 +475,8 @@ timeout_callback (gpointer data)
{
KibaLauncher *launcher = l->data;
gdk_window_move (launcher->window,
- launcher->object->position.x + 0.5,
- launcher->object->position.y + 0.5);
+ launcher->object->position.x + 0.5 - ICON_SIZE / 2,
+ launcher->object->position.y + 0.5 - ICON_SIZE / 2);
}
for (i = 0; i < 6; i++)
@@ -439,17 +519,14 @@ kiba_dock_init_model (KibaDock *dock, int width, int height)
dock->model.elasticity = 0.9;
dock->model.friction = 150;
- dock->model.gravity = 50;
dock->model.k = 0.8;
dock->model.constrain_iterations = 1;
- model_add_enclosing_rectangle (&dock->model, 0, 0, width - 50, height - 50);
-
- object = model_add_object (&dock->model, width / 2, height - 50, 0, NULL);
-
- dock->anchor =
- model_add_anchor (&dock->model, object, width / 2, height - 50);
+ model_add_enclosing_rectangle (&dock->model, ICON_SIZE / 2, ICON_SIZE / 2,
+ width - ICON_SIZE / 2, height - ICON_SIZE / 2);
+ object = model_add_object (&dock->model, 0, 0, 0, NULL);
+ dock->anchor = model_add_anchor (&dock->model, object, 0, 0 );
dock->mouse_anchor = model_add_anchor (&dock->model, NULL, 0, 0);
}
@@ -534,19 +611,20 @@ kiba_dock_motion_notify_event (GtkWidget *widget,
GdkModifierType state;
int x, y, new_x, new_y, dx, dy;
GdkScreen *screen;
- int screen_height;
+ int width, height;
screen = gdk_screen_get_default ();
- screen_height = gdk_screen_get_height (screen);
+ width = gdk_screen_get_width (screen);
+ height = gdk_screen_get_height (screen);
gdk_window_get_pointer (gdk_get_default_root_window(), &x, &y, &state);
- new_x = x - dock->drag_offset_x;
- new_y = y - dock->drag_offset_y;
+ new_x = x - dock->drag_offset_x + ICON_SIZE / 2;
+ new_y = y - dock->drag_offset_y + ICON_SIZE / 2;
dx = new_x - dock->mouse_anchor->x;
dy = new_y - dock->mouse_anchor->y;
- dock->mouse_anchor->x = new_x;
- dock->mouse_anchor->y = MIN (new_y, screen_height - 50);
+ dock->mouse_anchor->x = CLAMP (new_x, ICON_SIZE / 2, width - ICON_SIZE /2 );
+ dock->mouse_anchor->y = CLAMP (new_y, ICON_SIZE / 2, height - ICON_SIZE / 2);
dock->drag_distance += sqrt (dx * dx + dy * dy);
return TRUE;
diff --git a/main.c b/main.c
index f57adb0..e971805 100644
--- a/main.c
+++ b/main.c
@@ -21,7 +21,8 @@ model_init_constants (Model *model)
{
model->elasticity = 0.7;
model->friction = 8;
- model->gravity = 50;
+ model->gravity.x = 0;
+ model->gravity.y = 50;
model->k = 0.1;
model->constrain_iterations = 20;
}