⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xutil.cpp

📁 一个3D桌面的实现源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
////  Copyright (C) 2002 Brad Wasson <bard@systemtoolbox.com>////  This file is part of 3ddesktop.////  3ddesktop 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, or (at your option)//  any later version.////  3ddesktop 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 3ddesktop; see the file COPYING.   If not, write to//  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.////  ------- //  This is based very directly off of STPH by Rob Hodges.  I just//  ripped out only what I needed becase there was a lot of extra//  stuff there.  Thanks Rob!//#include "3ddesk.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <stdarg.h>#include "xutil.hpp"#include "util.h"#include <X11/Xlib.h>#include <X11/Xatom.h>#include <X11/Xutil.h>#include <X11/Xresource.h>#include <X11/extensions/xf86vmode.h>#include <X11/keysym.h>Bool error_handler_hit = False;static int ignore_all_errors_ehandler (Display *dpy, XErrorEvent *error);int VDesktops::init(Config *_cfg){    cfg = _cfg;    display = XOpenDisplay(NULL); /* Posix-compliant systems should behave sensibly with NULL here; */    if (display == NULL) {          /* but probably we should try harder for those that don't... */        msgout (ERROR, "Can not open display!\n");        return -1;    }#ifdef HAVE_KDE    int fake_argc = 1;    char *fake_argv[] = { "3ddeskd", NULL };    // FIXME: use destructor to delete!    // need to call this for the KWin calls to work    ka = new KApplication(display, fake_argc, fake_argv, "3ddesktop"); //main_argc, main_argv, "3ddesktop");#endif    screen = DefaultScreen(display);        root_win = RootWindow(display,screen);    XSetErrorHandler(ignore_all_errors_ehandler);    return 0;}void VDesktops::get_vdesktop_info (int *column, int *row,                                    int *n_columns, int *n_rows){    int c = 0, r = 0, nc = 0, nr = 0;#ifdef HAVE_KDE    if (cfg->use_kde) {        c = KWin::currentDesktop() - 1;	nc = KWin::numberOfDesktops();        nr = 1;    } else #endif // HAVE_KDE    if (cfg->sawfish_only) {        msgout(DEBUG, "vdesktops: sawfish only\n");        c = sawfish_get_current_workspace();        nc = sawfish_get_workspace_count();        nr = 1;    } else if (cfg->use_ewmh) {        msgout (DEBUG, "vdesktops: EWMH\n");        struct gnome_workspace_info wi;        ewmh_get_desktop_info (&wi);        c = wi.workspace;        nc = wi.workspace_count;        nr = 1;    } else if (cfg->use_viewareas) {        msgout(DEBUG, "vdesktops: areas\n");        struct gnome_area_info ai;        gnome_get_area_info(&ai);        c = ai.harea;        r = ai.varea;        nc = ai.harea_count;        nr = ai.varea_count;        if (nc == 1 && nr == 1 && cfg->use_workspaces) {            // try workspaces            struct gnome_workspace_info wi;            gnome_get_workspace_info (&wi);            c = wi.workspace;            nc = wi.workspace_count;            nr = 1;            if (nc <= 1)                 msgout (ERROR, "Could not find more then one virtual desktop!\n");        } else             cfg->use_workspaces = 0;            } else if (cfg->use_workspaces) {        msgout(DEBUG, "vdesktops: workspaces only\n");        struct gnome_workspace_info wi;        gnome_get_workspace_info (&wi);        c = wi.workspace;        nc = wi.workspace_count;        nr = 1;    } else {        // this is the default - make a best guess - ewmh, areas, workspaces        msgout (DEBUG, "vdesktops: making best guess...\n");        struct gnome_workspace_info wi;        ewmh_get_desktop_info (&wi);        c = wi.workspace;        nc = wi.workspace_count;        nr = 1;        if (nc == 1) {            struct gnome_area_info ai;            gnome_get_area_info(&ai);            c = ai.harea;            r = ai.varea;            nc = ai.harea_count;            nr = ai.varea_count;                    if (nc == 1 && nr == 1) {                // columns and rows is from workspaces                struct gnome_workspace_info wi;                gnome_get_workspace_info (&wi);                c = wi.workspace;                nc = wi.workspace_count;                nr = 1;                if (nc > 1) cfg->use_workspaces = 1;                else msgout (ERROR, "Could not find more then one virtual desktop!\n");            } else                 cfg->use_viewareas = 1;                        } else             cfg->use_ewmh = 1;                 }    msgout (DEBUG, "c=%d, r=%d, nc=%d, nr=%d\n",             c, r, nc, nr);    if (column)    *column = c;    if (row)       *row = r;    if (n_columns) *n_columns = nc;    if (n_rows)    *n_rows = nr;}int VDesktops::get_current_desktop (int *column, int *row){    get_vdesktop_info (column, row, 0, 0);    return 0;}int VDesktops::get_row_col_info (int *n_columns, int *n_rows){    get_vdesktop_info (0, 0, n_columns, n_rows);    return 0;}void VDesktops::set_vdesktop (int col, int row){#ifdef HAVE_KDE    if (cfg->use_kde) {        KWin::setCurrentDesktop(col + 1);        msgout (DEBUG, "vdesktops: switching to %d\n", col + 1);        XSync(display, 0);    } else #endif  // HAVE_KDE    if (cfg->sawfish_only) {        //msgout(DEBUG, "vdesktops: sawfish only\n");        sawfish_set_current_workspace (col);    } else if (cfg->use_workspaces) {        //msgout(DEBUG, "vdesktops: workspaces only\n");        gnome_set_current_workspace (col);    } else if (cfg->use_ewmh) {        ewmh_set_current_desktop (col);    } else if (cfg->use_viewareas) {        //msgout(DEBUG, "vdesktops: areas\n");        gnome_set_current_area (col, row);    } else {        msgout (DEBUG, "vdesktops: set: no type predetermined.\n");        gnome_set_current_area (col, row);            }}#if 0//===========================// pwm//===========================int VDesktops::pwm_get_current_workspace (void){    char *val;    long length;    Atom type;    int size;    Atom workspace_atom;    int ws;        workspace_atom = XInternAtom(display, "_PWM_WORKSPACE_NUM", False);    if (Get_Window_Property(display, root_win, workspace_atom,                            &length, &type, &size, &val))     {        msgout(ERROR, "get property PWM_WORKSPACE_NUM failed - setting one\n");        ws = 1;    } else {        ws = ((long *) val)[0];        XFree(val);    }    XSync(display, 0);    return ws;  // pwm has varea hardcoded as one atm}#if 0void VDesktops::pwm_set_current_workspace (int workspace){    int rc;    Atom area_atom;        area_atom = XInternAtom(display, "_PWM_WORKSPACE_NUM", False);        rc = send_client_message_32(display,                                root_win, root_win,                                area_atom,                                SubstructureNotifyMask,                                2,                                workspace,                                CurrentTime);    XSync(display, 0);    return;}#endifvoid VDesktops::pwm_set_current_workspace (int workspace){    CARD32 data[2];        data[0] = workspace;        Atom ws_atom = XInternAtom(display, "_PWM_WORKSPACE_NUM", False);        XChangeProperty(display, root_win, ws_atom, XA_INTEGER,                    32, PropModeReplace, (unsigned char*)data, 1);}int VDesktops::pwm_get_workspace_count (void){    char *val;    long length;    Atom type;    int size;    Atom workspace_atom;    int harea, varea;        workspace_atom = XInternAtom(display, "_PWM_WORKSPACE_INFO", False);    if (Get_Window_Property(display, root_win, workspace_atom,                            &length, &type, &size, &val))     {        msgout(ERROR, "get property PWM_WORKSPACE_INFO failed - setting one\n");        harea = 1;        varea = 1;    } else {        harea = ((long *) val)[0];        varea = ((long *) val)[1];        XFree(val);    }    XSync(display, 0);    return harea;  // pwm has varea hardcoded as one atm}#endif // if 0//===========================// gnome - areas//===========================void VDesktops::gnome_set_current_area (int harea, int varea){    int rc;    Atom area_atom;        area_atom = XInternAtom(display, "_WIN_AREA", False);        rc = send_client_message_32(display,                                root_win, root_win,                                area_atom,                                SubstructureNotifyMask,                                3,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -