Esempio n. 1
0
static gboolean
wnck_window_timeout_cb (WnckWindow *window)
{
        const gchar *game;
        gint x, y;
        gint width, height;
        gchar *sql;
        GError *error = NULL;

        if (wnck_window_is_fullscreen (window))
                goto exit;

        game = wnck_window_get_game (window);
        wnck_window_get_geometry (window, &x, &y, &width, &height);

        if (wnck_window_is_maximized (window))
                sql = g_strdup_printf (
                        "UPDATE window SET maximized = 1 "
                        "WHERE name = '%s'", game);
        else
                sql = g_strdup_printf (
                        "UPDATE window SET x = %d, y = %d, width = %d, "
                        "height = %d, maximized = 0 WHERE name = '%s'",
                        x, y, width, height, game);

        gva_db_execute (sql, &error);
        gva_error_handle (&error);
        g_free (sql);

exit:
        g_object_set_data (G_OBJECT (window), TIMEOUT_SOURCE_ID_KEY, NULL);

        return FALSE;
}
Esempio n. 2
0
int c_xywh(lua_State *lua)
{
	int top = lua_gettop(lua);

	if (top == 0) {
		// Return the xywh settings of the window

		WnckWindow *window = get_current_window();
		if (window != NULL) {

			int x, y, width, height;

			wnck_window_get_geometry(window, &x, &y, &width, &height);

			lua_pushnumber(lua, x);
			lua_pushnumber(lua, y);
			lua_pushnumber(lua, width);
			lua_pushnumber(lua, height);

			return 4;
		}

	} else if (top == 4) {
		// Set the xywh settings in the window


		int type1 = lua_type(lua, 1);
		int type2 = lua_type(lua, 2);
		int type3 = lua_type(lua, 3);
		int type4 = lua_type(lua, 4);

		if ((type1 != LUA_TNUMBER) ||
		        (type2 != LUA_TNUMBER) ||
		        (type3 != LUA_TNUMBER) ||
		        (type4 != LUA_TNUMBER)) {
			luaL_error(lua, "xywh: %s", four_indata_expected_error);
			return 0;
		}

		int x = lua_tonumber(lua, 1);
		int y = lua_tonumber(lua, 2);
		int xsize = lua_tonumber(lua, 3);
		int ysize = lua_tonumber(lua, 4);

		if (!devilspie2_emulate) {
			WnckWindow *window = get_current_window();

			set_window_geometry(window, x, y, xsize, ysize);
		}

		return 0;

	} else {
		luaL_error(lua, "xywh: %s", four_indata_expected_error);
		return 0;
	}

	return 0;
}
Esempio n. 3
0
int c_center(lua_State *lua)
{
	int top = lua_gettop(lua);

	int workspace_width, workspace_height, window_width, window_height;
	int xoffset, yoffset;
	WnckScreen *screen;
	WnckWorkspace *workspace;

	if (top != 0) {
		luaL_error(lua, "center: %s", no_indata_expected_error);
		return 0;
	}

	WnckWindow *window = get_current_window();

	if (!window) {
		lua_pushboolean(lua, FALSE);
		return 1;
	}

	wnck_window_get_geometry(window, NULL, NULL, &window_width, &window_height);

	screen = wnck_window_get_screen(window);

	workspace = wnck_screen_get_active_workspace(screen);

	if (workspace == NULL) {
		workspace = wnck_screen_get_workspace(screen,0);
	}

	if (workspace == NULL) {
		g_printerr(_("Could not get workspace"));
		lua_pushboolean(lua, FALSE);
		return 1;
	}

	workspace_width = wnck_workspace_get_width(workspace);
	workspace_height = wnck_workspace_get_height(workspace);

	xoffset = (workspace_width - window_width) / 2;
	yoffset = (workspace_height - window_height) / 2;

	devilspie2_error_trap_push();
	XMoveWindow (gdk_x11_get_default_xdisplay(),
	             wnck_window_get_xid(window),
	             xoffset, yoffset);

	if (devilspie2_error_trap_pop()) {
		g_printerr("center: %s", failed_string);
		lua_pushboolean(lua, FALSE);
		return 1;
	}

	lua_pushboolean(lua, TRUE);

	return 1;
}
Esempio n. 4
0
static int windowScreen(WnckWindow *window)
{
    // Check the window screen
    int x, y, width, height;
    wnck_window_get_geometry(window, &x, &y, &width, &height);
    const QRect windowRect(x, y, width, height);
    const QPoint pos = windowRect.center();
    return QApplication::desktop()->screenNumber(pos);
}
Esempio n. 5
0
/**
 * ww_window_center
 * @win:
 * @center_x:
 * @center_y:
 *
 * Return value: The return value is written to @center_x and @center_y and
 *               represents the center of gravity for @win
 */
static void
ww_window_center (WnckWindow *win, int *center_x, int *center_y)
{
	int x, y, w, h;

	wnck_window_get_geometry (win, &x, &y, &w, &h);
	*center_x = x + (w/2);
	*center_y = y + (h/2);	
}
Esempio n. 6
0
int c_xy(lua_State *lua)
{
	int top = lua_gettop(lua);

	if (top == 0) {
		// return the xy coordinates of the window

		WnckWindow *window = get_current_window();
		if (window != NULL) {

			int x, y, width, height;

			wnck_window_get_geometry(window, &x, &y, &width, &height);

			lua_pushnumber(lua, x);
			lua_pushnumber(lua, y);

			return 2;
		}

	} else if (top == 2) {
		// set the coordinates of the window

		int type1 = lua_type(lua, 1);
		int type2 = lua_type(lua, 2);

		if ((type1 != LUA_TNUMBER) ||
		        (type2 != LUA_TNUMBER)) {
			luaL_error(lua, "xy: %s", two_indata_expected_error);
			return 0;
		}

		int x = lua_tonumber(lua, 1);
		int y = lua_tonumber(lua, 2);

		if (!devilspie2_emulate) {

			WnckWindow *window = get_current_window();

			if (window) {
				wnck_window_set_geometry(window,
				                         WNCK_WINDOW_GRAVITY_CURRENT,
				                         WNCK_WINDOW_CHANGE_X + WNCK_WINDOW_CHANGE_Y,
				                         x, y, -1, -1);
			}
		}

	} else {
		luaL_error(lua, "xy: %s", two_indata_expected_error);
		return 0;
	}
	return 0;
}
Esempio n. 7
0
/**
 * return the geometry of the current window to the LUA script
 */
int c_get_window_geometry(lua_State *lua)
{
	int top = lua_gettop(lua);

	if (top != 0) {
		luaL_error(lua, "get_window_geometry: %s", no_indata_expected_error);
		return 0;
	}

	int x, y, width, height;

	WnckWindow *window = get_current_window();
	if (window)
	{
		wnck_window_get_geometry(window, &x, &y, &width, &height);
	}

	lua_pushnumber(lua, x);
	lua_pushnumber(lua, y);
	lua_pushnumber(lua, width);
	lua_pushnumber(lua, height);

	return 4;
}
Esempio n. 8
0
static void
item_activated_callback (GtkWidget *menu_item,
                         gpointer   data)
{
  WnckActionMenu *menu;
  WnckWindow *window;
  WindowAction action = GPOINTER_TO_INT (data);
  WnckScreen *screen;
  gboolean viewport_mode;

  menu = get_action_menu (menu_item);
  if (menu == NULL)
    return;

  window = menu->priv->window;

  screen = wnck_window_get_screen (window);
  viewport_mode = wnck_screen_get_workspace_count (screen) == 1 &&
                  wnck_workspace_is_virtual (wnck_screen_get_workspace (screen,
                                                                        0));

  switch (action)
    {
    case CLOSE:
      /* In an activate callback, so gtk_get_current_event_time() suffices */
      wnck_window_close (window,
			 gtk_get_current_event_time ());
      break;
    case MINIMIZE:
      if (wnck_window_is_minimized (window))
        wnck_window_unminimize (window,
                                gtk_get_current_event_time ());
      else
        wnck_window_minimize (window);
      break;
    case MAXIMIZE:
      if (wnck_window_is_maximized (window))
        wnck_window_unmaximize (window);
      else
        wnck_window_maximize (window);
      break;
    case ABOVE:
      if (wnck_window_is_above (window))
        wnck_window_unmake_above (window);
      else
        wnck_window_make_above (window);
      break;
    case MOVE:
      wnck_window_keyboard_move (window);
      break;
    case RESIZE:
      wnck_window_keyboard_size (window);
      break;
    case PIN:
      if (!viewport_mode)
        wnck_window_pin (window);
      else
        wnck_window_stick (window);
      break;
    case UNPIN:
      if (!viewport_mode)
        wnck_window_unpin (window);
      else
        wnck_window_unstick (window);
      break;
    case LEFT:
      if (!viewport_mode)
        {
          WnckWorkspace *workspace;
          workspace = wnck_workspace_get_neighbor (wnck_window_get_workspace (window),
                                                   WNCK_MOTION_LEFT);
          wnck_window_move_to_workspace (window, workspace);
        }
      else
        {
          int width, xw, yw, ww, hw;

          width = wnck_screen_get_width (screen);
          wnck_window_get_geometry (window, &xw, &yw, &ww, &hw);
          wnck_window_unstick (window);
          wnck_window_set_geometry (window, 0,
                                    WNCK_WINDOW_CHANGE_X | WNCK_WINDOW_CHANGE_Y,
                                    xw - width, yw,
                                    ww, hw);
        }
      break;
    case RIGHT:
      if (!viewport_mode)
        {
          WnckWorkspace *workspace;
          workspace = wnck_workspace_get_neighbor (wnck_window_get_workspace (window),
                                                   WNCK_MOTION_RIGHT);
          wnck_window_move_to_workspace (window, workspace);
        }
      else
        {
          int width, xw, yw, ww, hw;

          width = wnck_screen_get_width (screen);
          wnck_window_get_geometry (window, &xw, &yw, &ww, &hw);
          wnck_window_unstick (window);
          wnck_window_set_geometry (window, 0,
                                    WNCK_WINDOW_CHANGE_X | WNCK_WINDOW_CHANGE_Y,
                                    xw + width, yw,
                                    ww, hw);
        }
      break;
    case UP:
      if (!viewport_mode)
        {
          WnckWorkspace *workspace;
          workspace = wnck_workspace_get_neighbor (wnck_window_get_workspace (window),
                                                   WNCK_MOTION_UP);
          wnck_window_move_to_workspace (window, workspace);
        }
      else
        {
          int height, xw, yw, ww, hw;

          height = wnck_screen_get_height (screen);
          wnck_window_get_geometry (window, &xw, &yw, &ww, &hw);
          wnck_window_unstick (window);
          wnck_window_set_geometry (window, 0,
                                    WNCK_WINDOW_CHANGE_X | WNCK_WINDOW_CHANGE_Y,
                                    xw, yw - height,
                                    ww, hw);
        }
      break;
    case DOWN:
      if (!viewport_mode)
        {
          WnckWorkspace *workspace;
          workspace = wnck_workspace_get_neighbor (wnck_window_get_workspace (window),
                                                   WNCK_MOTION_DOWN);
          wnck_window_move_to_workspace (window, workspace);
        }
      else
        {
          int height, xw, yw, ww, hw;

          height = wnck_screen_get_height (screen);
          wnck_window_get_geometry (window, &xw, &yw, &ww, &hw);
          wnck_window_unstick (window);
          wnck_window_set_geometry (window, 0,
                                    WNCK_WINDOW_CHANGE_X | WNCK_WINDOW_CHANGE_Y,
                                    xw, yw + height,
                                    ww, hw);
        }
      break;
    case MOVE_TO_WORKSPACE:
      if (!viewport_mode)
        {
          int workspace_index;
          WnckWorkspace *workspace;

          workspace_index = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item),
                                                                "workspace"));

          workspace = wnck_screen_get_workspace (screen, workspace_index);
          wnck_window_move_to_workspace (window, workspace);
        }
      else
        {
          WnckWorkspace *workspace;
          int new_viewport_x, new_viewport_y;
          int width, height;
          int xw, yw, ww, hw;
          int viewport_x, viewport_y;

          new_viewport_x = GPOINTER_TO_INT (
                                      g_object_get_data (G_OBJECT (menu_item),
                                                         "viewport_x"));
          new_viewport_y = GPOINTER_TO_INT (
                                      g_object_get_data (G_OBJECT (menu_item),
                                                         "viewport_y"));

          workspace = wnck_screen_get_workspace (screen, 0);

          width = wnck_screen_get_width (screen);
          height = wnck_screen_get_height (screen);

          wnck_window_get_geometry (window, &xw, &yw, &ww, &hw);

          viewport_x = wnck_workspace_get_viewport_x (workspace);
          viewport_y = wnck_workspace_get_viewport_y (workspace);

          wnck_window_unstick (window);
          wnck_window_set_geometry (window, 0,
                                    WNCK_WINDOW_CHANGE_X | WNCK_WINDOW_CHANGE_Y,
                                    xw + new_viewport_x - viewport_x,
                                    yw + new_viewport_y - viewport_y,
                                    ww, hw);
        }
      break;
    default:
      g_assert_not_reached ();
    }
}
Esempio n. 9
0
int c_set_viewport(lua_State *lua)
{
	int top = lua_gettop(lua);
	WnckScreen *screen;
	int x,y,width,height, viewport_start;

	if (top != 1) {
		luaL_error(lua, "set_viewport: %s", one_indata_expected_error);
		return 0;
	}

	int type = lua_type(lua, 1);
	if (type != LUA_TNUMBER) {
		luaL_error(lua, "set_viewport: %s", number_expected_as_indata_error);
		return 0;
	}

	int num = lua_tonumber(lua,1);

	if (num <= 0) {
		g_error("set_viewport: %s", integer_greater_than_zero_expected_error);
		lua_pushboolean(lua, FALSE);
		return 1;
	}

	WnckWindow *window = get_current_window();

	if (!window) {
		lua_pushboolean(lua, FALSE);
		return 1;
	}

	screen = wnck_window_get_screen(window);

	wnck_window_get_geometry(window, &x, &y, &width, &height);

	gulong xid = wnck_window_get_xid(window);

	viewport_start = devilspie2_get_viewport_start(xid);
	if (viewport_start < 0) {
		g_printerr("set_viewport: %s", could_not_find_current_viewport_error);
		lua_pushboolean(lua, FALSE);
		return 1;
	}

	x=((num-1) * wnck_screen_get_width(screen)) - viewport_start + x;

	devilspie2_error_trap_push();
	XMoveResizeWindow(gdk_x11_get_default_xdisplay(),
	                  wnck_window_get_xid(window),
	                  x, y, width, height);

	if (devilspie2_error_trap_pop()) {
		g_printerr("set_viewport: %s", setting_viewport_failed_error);
		lua_pushboolean(lua, FALSE);
		return 1;
	}

	lua_pushboolean(lua, TRUE);
	return 1;
}
Esempio n. 10
0
static void
wnck_window_initialize (WnckWindow *window)
{
        const gchar *game;
        sqlite3_stmt *stmt;
        gchar *sql;
        gint errcode;
        gboolean success;
        GError *error = NULL;

        game = wnck_window_get_game (window);

        sql = g_strdup_printf (SQL_SELECT_GAME_WINDOW, game);
        success = gva_db_prepare (sql, &stmt, &error);
        gva_error_handle (&error);
        g_free (sql);

        if (!success)
                return;

        errcode = sqlite3_step (stmt);

        /* Restore the window's previous geometry. */
        if (errcode == SQLITE_ROW)
        {
                gint x, y;
                gint width, height;
                gboolean maximized;

                x = sqlite3_column_int (stmt, COLUMN_X);
                y = sqlite3_column_int (stmt, COLUMN_Y);
                width = sqlite3_column_int (stmt, COLUMN_WIDTH);
                height = sqlite3_column_int (stmt, COLUMN_HEIGHT);
                maximized = sqlite3_column_int (stmt, COLUMN_MAXIMIZED);

                wnck_window_set_geometry (
                        window, WNCK_WINDOW_GRAVITY_CURRENT,
                        WNCK_WINDOW_CHANGE_X | WNCK_WINDOW_CHANGE_Y |
                        WNCK_WINDOW_CHANGE_WIDTH | WNCK_WINDOW_CHANGE_HEIGHT,
                        x, y, width, height);

                if (maximized)
                        wnck_window_maximize (window);
                else
                        wnck_window_unmaximize (window);
        }

        /* Create a new record using the current geometry. */
        else if (errcode == SQLITE_DONE)
        {
                gint x, y;
                gint width, height;
                gboolean maximized;

                maximized = wnck_window_is_maximized (window);
                wnck_window_get_geometry (window, &x, &y, &width, &height);

                sql = g_strdup_printf (
                        "INSERT INTO window VALUES "
                        "('%s', %d, %d, %d, %d, %d)",
                        game, x, y, width, height, maximized);
                gva_db_execute (sql, &error);
                gva_error_handle (&error);
                g_free (sql);
        }

        /* Something went wrong. */
        else
        {
                gva_db_set_error (&error, 0, NULL);
                gva_error_handle (&error);
        }

        sqlite3_finalize (stmt);
}
Esempio n. 11
0
/**
 * ww_find_neighbour
 * @screen:
 * @windows:
 * @active:
 * @direction:
 *
 * Return value: The neighbouring window from @windows in the given direction
 *               or %NULL in case no window is found or @active is %NULL
 */
WnckWindow*
ww_find_neighbour (WnckScreen	*screen,
                   GList		*windows,
                   WnckWindow	*active,
                   WwDirection	direction)
{
	WnckWindow	*neighbour;
	GList		*next;
	int			ax, ay, aw, ah; /* active window geometry */
	int			wx, wy; /* geometry for currently checked window */ 
	int			nx, ny; /* geometry of neighbour */
	double		wdist, ndist; /* distance to active window */

	neighbour = NULL;
	
	g_return_val_if_fail (WNCK_IS_SCREEN(screen), NULL);
	
	if (g_list_length(windows) == 0)
    {
		return NULL;
    }
	
	/* If there is no active window, do nothing */
	if (active == NULL
		|| wnck_window_is_skip_tasklist (active)) {
		g_debug ("No active window");
		return NULL;
	}

	nx = ny = 0;
	ndist = 100000;

	wnck_window_get_geometry (active, &ax, &ay, &aw, &ah);
	g_debug("Active window '%s' (%d, %d) @ %d x %d",
	        wnck_window_get_name (active), ax, ay, aw, ah);

	/* Set ax and ay to the center of grav. for active */
	ww_window_center (active, &ax, &ay);
	
	if ( direction == LEFT )
	{
		for ( next = windows; next; next = next->next )
		{
			ww_window_center (WNCK_WINDOW (next->data), &wx, &wy);
			wdist = ww_y_weighted_distance (wx, wy, ax, ay);
			if ( wx < ax )
			{
				if ( wdist < ndist )
				{
					neighbour = WNCK_WINDOW (next->data);
					ndist = wdist;
				}
			} 
		}
	}
	else if ( direction == RIGHT )
	{
		for ( next = windows; next; next = next->next )
		{
			ww_window_center (WNCK_WINDOW (next->data), &wx, &wy);
			wdist = ww_y_weighted_distance (wx, wy, ax, ay);
			if ( wx > ax )
			{
				if ( wdist < ndist )
				{
					neighbour = WNCK_WINDOW (next->data);
					ndist = wdist;
				}
			}
		}
	}
	else if ( direction == DOWN )
	{
		for ( next = windows; next; next = next->next )
		{
			ww_window_center (WNCK_WINDOW (next->data), &wx, &wy);
			wdist = ww_x_weighted_distance (wx, wy, ax, ay);
			if ( wy > ay )
			{
				if ( wdist < ndist )
				{
					neighbour = WNCK_WINDOW (next->data);
					ndist = wdist;
				}
			}
		}
	}
	else if ( direction == UP )
	{
		for ( next = windows; next; next = next->next )
		{
			ww_window_center (WNCK_WINDOW (next->data), &wx, &wy);
			wdist = ww_x_weighted_distance (wx, wy, ax, ay);
			if ( wy < ay )
			{
				if ( wdist < ndist )
				{
					neighbour = WNCK_WINDOW (next->data);
					ndist = wdist;
				}
			}
		}
	}

	if (neighbour)
		g_debug ("Found neighbour '%s'",
		         wnck_window_get_name (neighbour));
	
	return neighbour; 
}
Esempio n. 12
0
/**
 * ww_calc_bounds
 * @screen: The screen for which to calculate the bounds
 * @struts: A list of %WnckWindow<!---->s that should be treated as
 *          blocking elements on the desktop. Eg. panels and docks
 * @x: Return value for the left side of the bounding box
 * @y: Return value for the top of the box
 * @right: Return coordinate for the right side of the bounding box
 * @bottom: Return value for the bottom coordinate of the bounding box
 *
 * Calculate the maximal rect within a set of blocking windows.
 * For simplicity this method assumes that all struts are along the screen
 * edges and expand over the entire screen edge. Ie a standard panel setup.
 */
void
ww_calc_bounds (WnckScreen *screen,
                GList *struts, 
                int *left, 
                int *top, 
                int *right, 
                int *bottom)
{
	GList		*next;
	WnckWindow  *win;
	int wx, wy, ww, wh; /* current window geom */
	int edge_l, edge_t, edge_b, edge_r;
	int screen_w, screen_h;
	
	edge_l = 0;
	edge_t = 0;
	edge_r = wnck_screen_get_width (screen);
	edge_b = wnck_screen_get_height (screen);
	
	screen_w = edge_r;
	screen_h = edge_b;
	
	for (next = struts; next; next = next->next)
	{	
		win = WNCK_WINDOW (next->data);
		wnck_window_get_geometry (win, &wx, &wy, &ww, &wh);
		
		/* Left side strut */
		if (is_high(ww, wh) && wx == 0) {
			edge_l = MAX(edge_l, ww);
		}
		
		/* Top struct */
		else if (is_broad(ww, wh) && wy == 0) {
			edge_t = MAX (edge_t, wh);
		}
		
		/* Right side strut */
		else if (is_high(ww, wh) && (wx+ww) == screen_w) {
			edge_r = MIN(edge_r, wx);
		}
		
		/* Bottom struct */
		else if (is_broad(ww, wh) && (wy+wh) == screen_h) {
			edge_b = MIN (edge_b, wy);
		}
		
		else {
			g_warning ("Desktop layout contains floating element at "
					   "(%d, %d)@%dx%d", wx, wy, ww, wh);
		}
	}
	
	g_debug ("Calculated desktop bounds (%d, %d), (%d, %d)",
			 edge_l, edge_t, edge_r, edge_b);
	
	*left = edge_l;
	*top = edge_t;
	*right = edge_r;
	*bottom = edge_b;
}
static void
task_manager_dalog_disp_preview (TaskManagerDialog *dialog) 
{
  gint height;
  gint width;
  gint data_length;

  gint win_x,win_y,win_width,win_height;
  GtkAllocation allocation;
  GList * iter = NULL;
  gint win_count = 0;
  int i = 0;
  TaskManagerDialogPrivate * priv = GET_PRIVATE (dialog);
  GtkPositionType pos_type = awn_applet_get_pos_type (priv->applet);
  GtkOrientation current_orientation;
  gdouble scale;
  glong total_width = 0;
  glong screen_width = gdk_screen_get_width (gdk_screen_get_default ());
  glong screen_height = gdk_screen_get_height (gdk_screen_get_default ());
  
  
  current_orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (priv->items_box));
  if ( (current_orientation == GTK_ORIENTATION_VERTICAL) &&
      (( pos_type == GTK_POS_BOTTOM) || (pos_type == GTK_POS_TOP)) )
  {
    gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->items_box),GTK_ORIENTATION_HORIZONTAL);
  }
  else if ( (current_orientation == GTK_ORIENTATION_HORIZONTAL)&&
      (( pos_type == GTK_POS_LEFT) || (pos_type == GTK_POS_RIGHT)) )
  {
    gtk_orientable_set_orientation (GTK_ORIENTABLE (priv->items_box),GTK_ORIENTATION_VERTICAL);
  }
  for (iter = g_list_first(priv->children); iter; iter=iter->next)
  {
    if (TASK_IS_WINDOW(iter->data))
    {
      win_count++;
    }
  }
  if (priv->data)
  {
    g_free (priv->data);
  }
  data_length =  win_count*6 +1;
  priv->data = g_new0 (long, data_length);
  priv->data[0] = (long) win_count;
  scale = priv->dialog_scale;

scaled_down:
  total_width = 0;
  if (screen_width && screen_height)
  {
    for (iter = g_list_first(priv->children); iter; iter=iter->next)
    {
      if (TASK_IS_WINDOW(iter->data))
      {
        wnck_window_get_geometry (task_window_get_window (iter->data),
                                  &win_x,
                                  &win_y,
                                  &win_width,
                                  &win_height);

        gtk_widget_get_allocation (GTK_WIDGET(iter->data), &allocation);
        if ((pos_type == GTK_POS_TOP) || (pos_type == GTK_POS_BOTTOM))
        {
          /*conditional operator alert*/
          height = gdk_screen_height () / (win_count?1.0/scale:1.0/scale+(win_count-2));

          width = ((float)win_width) / ((float)win_height) * height;
          total_width = total_width + width;
          if (total_width > screen_width * 0.9)
          {
            scale = scale * 0.9;
            goto scaled_down;
          }
        }
        else
        {
          /*conditional operator alert*/
          width = gdk_screen_width () / (win_count<4?1.0/scale+1:1.0/scale+1+(win_count-3));
          height = ((float)win_height) / ((float)win_width) * width;
          total_width = total_width + height;
          if (total_width > screen_height * 0.9)
          {
            scale = scale * 0.9;
            goto scaled_down;
          }
        }
      }
    }
  }
  
  for (iter = g_list_first(priv->children); iter; iter=iter->next)
  {
    if (TASK_IS_WINDOW(iter->data))
    {
      wnck_window_get_geometry (task_window_get_window (iter->data),
                                &win_x,
                                &win_y,
                                &win_width,
                                &win_height);

      gtk_widget_get_allocation (GTK_WIDGET(iter->data), &allocation);
      gtk_widget_set_tooltip_text (GTK_WIDGET (iter->data),
                                   task_window_get_name(TASK_WINDOW(iter->data)));
      /* Change these calculations. Ultimately we can be much smarter about
       layout.  After a certain point it will involve adding some more
       containers in our container....*/
      if ((pos_type == GTK_POS_TOP) || (pos_type == GTK_POS_BOTTOM))
      {
        /*conditional operator alert*/
        height = gdk_screen_height () / (win_count?1.0/scale:1.0/scale+(win_count-2));

        width = ((float)win_width) / ((float)win_height) * height;
        gtk_widget_set_size_request (GTK_WIDGET(iter->data), width, height);
      }
      else
      {
        /*conditional operator alert*/
        width = gdk_screen_width () / (win_count<4?1.0/scale+1:1.0/scale+1+(win_count-3));
        height = ((float)win_height) / ((float)win_width) * width;
        gtk_widget_set_size_request (GTK_WIDGET(iter->data), width, height);
      }      	
	    priv->data[i*6+1] = (long) 5;
	    priv->data[i*6+2] = (long) task_window_get_xid (TASK_WINDOW(iter->data));
	    priv->data[i*6+3] = (long) allocation.x+4;
	    priv->data[i*6+4] = (long) allocation.y+4;
	    priv->data[i*6+5] = (long) width-8;
	    priv->data[i*6+6] = (long) height-8;
      i++;
    }
  }

	gdk_property_change ((GTK_WIDGET(dialog))->window, 
					priv->kde_a,
 					priv->kde_a,
					32, 
					GDK_PROP_MODE_REPLACE, 
					(guchar*) priv->data,
					data_length);
}
Esempio n. 14
0
static gboolean
update_menu_state (WnckActionMenu *menu)
{
  WnckActionMenuPrivate *priv;
  WnckWindowActions      actions;
  WnckScreen            *screen;
  WnckWorkspace         *workspace;
  gboolean               viewport_mode;
  gboolean               move_workspace_sensitive;

  priv = menu->priv;

  priv->idle_handler = 0;

  actions = wnck_window_get_actions (priv->window);
  screen  = wnck_window_get_screen  (priv->window);

  viewport_mode = wnck_screen_get_workspace_count (screen) == 1 &&
                  wnck_workspace_is_virtual (wnck_screen_get_workspace (screen,
                                                                        0));
  move_workspace_sensitive = viewport_mode ||
                             (actions & WNCK_WINDOW_ACTION_CHANGE_WORKSPACE) != 0;

  if (wnck_window_is_minimized (priv->window))
    {
      set_item_text (priv->minimize_item, _("Unmi_nimize"));
      set_item_stock (priv->minimize_item, NULL);
      gtk_widget_set_sensitive (priv->minimize_item,
                                (actions & WNCK_WINDOW_ACTION_UNMINIMIZE) != 0);
    }
  else
    {
      set_item_text (priv->minimize_item, _("Mi_nimize"));
      set_item_stock (priv->minimize_item, WNCK_STOCK_MINIMIZE);
      gtk_widget_set_sensitive (priv->minimize_item,
                                (actions & WNCK_WINDOW_ACTION_MINIMIZE) != 0);
    }

  if (wnck_window_is_maximized (priv->window))
    {
      set_item_text (priv->maximize_item, _("Unma_ximize"));
      set_item_stock (priv->maximize_item, NULL);
      gtk_widget_set_sensitive (priv->maximize_item,
                                (actions & WNCK_WINDOW_ACTION_UNMAXIMIZE) != 0);
    }
  else
    {
      set_item_text (priv->maximize_item, _("Ma_ximize"));
      set_item_stock (priv->maximize_item, WNCK_STOCK_MAXIMIZE);
      gtk_widget_set_sensitive (priv->maximize_item,
                                (actions & WNCK_WINDOW_ACTION_MAXIMIZE) != 0);
    }

  g_signal_handlers_block_by_func (G_OBJECT (priv->above_item),
                                   item_activated_callback,
                                   GINT_TO_POINTER (ABOVE));
  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (priv->above_item),
                                  wnck_window_is_above (priv->window));
  g_signal_handlers_unblock_by_func (G_OBJECT (priv->above_item),
                                     item_activated_callback,
                                     GINT_TO_POINTER (ABOVE));

  gtk_widget_set_sensitive (priv->above_item,
                            (actions & WNCK_WINDOW_ACTION_ABOVE) != 0);

  g_signal_handlers_block_by_func (G_OBJECT (priv->pin_item),
                                   item_activated_callback,
                                   GINT_TO_POINTER (PIN));
  g_signal_handlers_block_by_func (G_OBJECT (priv->unpin_item),
                                   item_activated_callback,
                                   GINT_TO_POINTER (UNPIN));
  if ((viewport_mode  && wnck_window_is_sticky (priv->window)) ||
      (!viewport_mode && wnck_window_is_pinned (priv->window)))
          gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (priv->pin_item),
                                          TRUE);
  else
          gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (priv->unpin_item),
                                          TRUE);
  g_signal_handlers_unblock_by_func (G_OBJECT (priv->pin_item),
                                     item_activated_callback,
                                     GINT_TO_POINTER (PIN));
  g_signal_handlers_unblock_by_func (G_OBJECT (priv->unpin_item),
                                     item_activated_callback,
                                     GINT_TO_POINTER (UNPIN));

  gtk_widget_set_sensitive (priv->pin_item,
                            move_workspace_sensitive);

  gtk_widget_set_sensitive (priv->unpin_item,
                            move_workspace_sensitive);

  gtk_widget_set_sensitive (priv->close_item,
                            (actions & WNCK_WINDOW_ACTION_CLOSE) != 0);

  gtk_widget_set_sensitive (priv->move_item,
                            (actions & WNCK_WINDOW_ACTION_MOVE) != 0);

  gtk_widget_set_sensitive (priv->resize_item,
                            (actions & WNCK_WINDOW_ACTION_RESIZE) != 0);

  gtk_widget_set_sensitive (priv->workspace_item,
                            move_workspace_sensitive);

  gtk_widget_set_sensitive (priv->left_item,
                            move_workspace_sensitive);
  gtk_widget_set_sensitive (priv->right_item,
                            move_workspace_sensitive);
  gtk_widget_set_sensitive (priv->up_item,
                            move_workspace_sensitive);
  gtk_widget_set_sensitive (priv->down_item,
                            move_workspace_sensitive);

  workspace = wnck_window_get_workspace (priv->window);

  if (viewport_mode && !wnck_window_is_sticky (priv->window))
    {
      int window_x, window_y;
      int viewport_x, viewport_y;
      int viewport_width, viewport_height;
      int screen_width, screen_height;

      if (!workspace)
        workspace = wnck_screen_get_workspace (screen, 0);

      wnck_window_get_geometry (priv->window, &window_x, &window_y, NULL, NULL);

      viewport_x = wnck_workspace_get_viewport_x (workspace);
      viewport_y = wnck_workspace_get_viewport_y (workspace);

      window_x += viewport_x;
      window_y += viewport_y;

      viewport_width = wnck_workspace_get_width (workspace);
      viewport_height = wnck_workspace_get_height (workspace);

      screen_width = wnck_screen_get_width (screen);
      screen_height = wnck_screen_get_height (screen);

      if (window_x >= screen_width)
        gtk_widget_show (priv->left_item);
      else
        gtk_widget_hide (priv->left_item);

      if (window_x < viewport_width - screen_width)
        gtk_widget_show (priv->right_item);
      else
        gtk_widget_hide (priv->right_item);

      if (window_y >= screen_height)
        gtk_widget_show (priv->up_item);
      else
        gtk_widget_hide (priv->up_item);

      if (window_y < viewport_height - screen_height)
        gtk_widget_show (priv->down_item);
      else
        gtk_widget_hide (priv->down_item);
    }
  else if (!viewport_mode && workspace && !wnck_window_is_pinned (priv->window))
    {
      if (wnck_workspace_get_neighbor (workspace, WNCK_MOTION_LEFT))
        gtk_widget_show (priv->left_item);
      else
        gtk_widget_hide (priv->left_item);

      if (wnck_workspace_get_neighbor (workspace, WNCK_MOTION_RIGHT))
        gtk_widget_show (priv->right_item);
      else
        gtk_widget_hide (priv->right_item);

      if (wnck_workspace_get_neighbor (workspace, WNCK_MOTION_UP))
        gtk_widget_show (priv->up_item);
      else
        gtk_widget_hide (priv->up_item);

      if (wnck_workspace_get_neighbor (workspace, WNCK_MOTION_DOWN))
        gtk_widget_show (priv->down_item);
      else
        gtk_widget_hide (priv->down_item);
    }
  else
    {
      gtk_widget_hide (priv->left_item);
      gtk_widget_hide (priv->right_item);
      gtk_widget_hide (priv->up_item);
      gtk_widget_hide (priv->down_item);
    }

  if (viewport_mode)
    {
      int viewport_width, viewport_height;
      int screen_width, screen_height;

      viewport_width = wnck_workspace_get_width (workspace);
      viewport_height = wnck_workspace_get_height (workspace);

      screen_width = wnck_screen_get_width (screen);
      screen_height = wnck_screen_get_height (screen);

      gtk_widget_show (priv->workspace_separator);
      gtk_widget_show (priv->pin_item);
      gtk_widget_show (priv->unpin_item);
      if (viewport_width  >= 2 * screen_width ||
          viewport_height >= 2 * screen_height)
        {
          gtk_widget_show (priv->workspace_item);
          refill_submenu_viewport (menu);
        }
      else
        {
          gtk_widget_hide (priv->workspace_item);
          gtk_menu_popdown (GTK_MENU (gtk_menu_item_get_submenu (GTK_MENU_ITEM (priv->workspace_item))));
        }
    }
  else if (wnck_screen_get_workspace_count (screen) > 1)
    {
      gtk_widget_show (priv->workspace_separator);
      gtk_widget_show (priv->pin_item);
      gtk_widget_show (priv->unpin_item);
      gtk_widget_show (priv->workspace_item);
      refill_submenu_workspace (menu);
    }
  else
    {
      gtk_widget_hide (priv->workspace_separator);
      gtk_widget_hide (priv->pin_item);
      gtk_widget_hide (priv->unpin_item);
      gtk_widget_hide (priv->workspace_item);
      gtk_menu_popdown (GTK_MENU (gtk_menu_item_get_submenu (GTK_MENU_ITEM (priv->workspace_item))));
    }

  gtk_menu_reposition (GTK_MENU (menu));

  return FALSE;
}
static gboolean
on_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
  GdkGC *gc;
  XTransform transform;
  double scale;
  int wx, wy, ww, wh;
  int frame_left, frame_right, frame_top, frame_bottom;
  int thumbnail_width, thumbnail_height;
  int offset_x, offset_y;
  SSWindow *window;
  SSThumbnailer *thumbnailer;
  Display *display;
  display = gdk_x11_get_default_xdisplay ();
  thumbnailer = (SSThumbnailer *) data;
  window = thumbnailer->window;

  if (thumbnailer->thumbnail_pixmap == NULL) {
    initialize_thumbnailer_pictures (thumbnailer);
  }
  gc = gdk_gc_new (thumbnailer->thumbnail_pixmap);

  ss_xinerama_get_frame_extents (
      // TODO - should we cut out the ->workspace in the line below?
      window->workspace->screen->xinerama, window,
      &frame_left, &frame_right, &frame_top, &frame_bottom);

  wnck_window_get_geometry (window->wnck_window, &wx, &wy, &ww, &wh);

  scale = ww > wh ? ww : wh;
  scale /= (double) THUMBNAIL_SIZE;
  thumbnail_width = thumbnail_height = THUMBNAIL_SIZE;
  if (ww > wh) {
    thumbnail_height = wh * THUMBNAIL_SIZE / ww;
  } else {
    thumbnail_width = ww * THUMBNAIL_SIZE / wh;
  }
  
  transform.matrix[0][0] = XDoubleToFixed (scale);
  transform.matrix[0][1] = XDoubleToFixed (0.0);
  transform.matrix[0][2] = XDoubleToFixed (-frame_left * (scale - 1.0));
  transform.matrix[1][0] = XDoubleToFixed (0.0);
  transform.matrix[1][1] = XDoubleToFixed (scale);
  transform.matrix[1][2] = XDoubleToFixed (-frame_top * (scale - 1.0));
  transform.matrix[2][0] = XDoubleToFixed (0.0);
  transform.matrix[2][1] = XDoubleToFixed (0.0);
  transform.matrix[2][2] = XDoubleToFixed (1.0);
  XRenderSetPictureTransform (display, thumbnailer->window_picture,
      &transform);

  XRenderComposite (display, PictOpSrc,
    thumbnailer->window_picture, None, thumbnailer->thumbnail_picture,
    0, 0, 0, 0, 0, 0, THUMBNAIL_SIZE, THUMBNAIL_SIZE);

  offset_x = widget->allocation.x + (THUMBNAIL_SIZE - thumbnail_width) / 2;
  offset_y = widget->allocation.y + (THUMBNAIL_SIZE - thumbnail_height) / 2;

  gdk_draw_drawable (thumbnailer->drawing_area->window, gc,
      thumbnailer->thumbnail_pixmap, 0, 0,
      offset_x, offset_y, thumbnail_width, thumbnail_height);

  gdk_draw_rectangle (thumbnailer->drawing_area->window,
      thumbnailer->drawing_area->style->black_gc, FALSE,
      offset_x, offset_y, thumbnail_width - 1, thumbnail_height - 1);

  g_object_unref (gc);
  return FALSE;
}
Esempio n. 16
0
static void
refill_submenu_viewport (WnckActionMenu *menu)
{
  GtkWidget *submenu;
  GList *children;
  GList *l;
  WnckScreen *screen;
  WnckWorkspace *workspace;
  int window_x, window_y;
  int viewport_x, viewport_y;
  int viewport_width, viewport_height;
  int screen_width, screen_height;
  int x, y;
  int number;

  submenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu->priv->workspace_item));

  /* Remove existing items */
  children = gtk_container_get_children (GTK_CONTAINER (submenu));
  for (l = children; l; l = l->next)
    gtk_container_remove (GTK_CONTAINER (submenu), l->data);
  g_list_free (children);

  screen = wnck_window_get_screen (menu->priv->window);
  workspace = wnck_screen_get_workspace (screen, 0);

  wnck_window_get_geometry (menu->priv->window,
                            &window_x, &window_y, NULL, NULL);

  viewport_x = wnck_workspace_get_viewport_x (workspace);
  viewport_y = wnck_workspace_get_viewport_y (workspace);

  window_x += viewport_x;
  window_y += viewport_y;

  viewport_width = wnck_workspace_get_width (workspace);
  viewport_height = wnck_workspace_get_height (workspace);

  screen_width = wnck_screen_get_width (screen);
  screen_height = wnck_screen_get_height (screen);

  number = 1;
  for (y = 0; y < viewport_height; y += screen_height)
    {
      char      *label;
      GtkWidget *item;

      for (x = 0; x < viewport_width; x += screen_width)
        {
          /* Keep this in sync with what is in get_workspace_name_with_accel()
           */
          if (number == 10)
            label = g_strdup_printf (_("Workspace 1_0"));
          else
            label = g_strdup_printf (_("Workspace %s%d"),
                                     number < 10 ? "_" : "",
                                     number);
          number++;

          item = make_menu_item (MOVE_TO_WORKSPACE);
          g_object_set_data (G_OBJECT (item), "viewport_x",
                             GINT_TO_POINTER (x));
          g_object_set_data (G_OBJECT (item), "viewport_y",
                             GINT_TO_POINTER (y));

          if (window_x >= x && window_x < x + screen_width &&
              window_y >= y && window_y < y + screen_height)
            gtk_widget_set_sensitive (item, FALSE);

          gtk_menu_shell_append (GTK_MENU_SHELL (submenu), item);
          set_item_text (item, label);
          set_item_stock (item, NULL);

          g_free (label);
        }
    }

  gtk_menu_reposition (GTK_MENU (submenu));
}
Esempio n. 17
0
static gboolean
on_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer data)
{
  SSWorkspace *workspace;
  int screen_width, screen_height;
  double width_ratio, height_ratio;
  int x, y, w, h;
  int viewport_x;
  GList *i;
  SSWindow *active_window;
  WnckWindow *wnck_window;
  int state;
  GdkRectangle r;

  workspace = (SSWorkspace *) data;
  screen_width  = workspace->screen->screen_width;
  screen_height = workspace->screen->screen_height;
  active_window = workspace->screen->active_window;

  x = widget->allocation.x;
  y = widget->allocation.y;
  w = widget->allocation.width;
  h = widget->allocation.height;

  state = (workspace == workspace->screen->active_workspace) ? GTK_STATE_SELECTED : GTK_STATE_NORMAL;
  gdk_draw_rectangle (widget->window,
    widget->style->dark_gc[state], TRUE,
    1, 1, w-2, h-2);
  gdk_draw_rectangle (widget->window,
    widget->style->base_gc[state], FALSE,
    0, 0, w-1, h-1);

  width_ratio  = (double) w / (double) screen_width;
  height_ratio = (double) h / (double) screen_height;

  viewport_x = 0;
  if (window_manager_uses_viewports) {
    viewport_x = wnck_workspace_get_viewport_x (workspace->wnck_workspace);
  }

  for (i = workspace->screen->wnck_windows_in_stacking_order; i; i = i->next) {
    wnck_window = (WnckWindow *) i->data;
    if (wnck_window_get_workspace (wnck_window) != workspace->wnck_workspace) {
      continue;
    }
    if (wnck_window_is_minimized (wnck_window)) {
      continue;
    }

    state = GTK_STATE_ACTIVE;
    if ((active_window != NULL) &&
      ((wnck_window_get_xid (wnck_window) == wnck_window_get_xid (active_window->wnck_window)))) {
      state = GTK_STATE_SELECTED;
    }
    wnck_window_get_geometry (wnck_window, &r.x, &r.y, &r.width, &r.height);
    if (window_manager_uses_viewports) {
      r.x += viewport_x - (workspace->viewport * workspace->screen->screen_width);
    }

    r.x = 0.5 + r.x * width_ratio;
    r.y = 0.5 + r.y * height_ratio;
    r.width  = 0.5 + r.width  * width_ratio;
    r.height = 0.5 + r.height * height_ratio;

    if (r.width < 3) {
      r.width = 3;
    }
    if (r.height < 3) {
      r.height = 3;
    }

    gdk_draw_rectangle (widget->window,
      widget->style->bg_gc[state], TRUE,
      r.x+1, r.y+1, r.width-2, r.height-2);
    gdk_draw_rectangle (widget->window,
      widget->style->fg_gc[state], FALSE,
      r.x,   r.y,   r.width-1, r.height-1);
  }

  on_expose_event_draw_text (widget, workspace);
  return FALSE;
}