Spicy 修改代码 实现双屏显示以及鼠标键盘绑定

Wesley13
• 阅读 774

修改 spicy.c 

static SpiceWindow*create_spice_window(spice_connection *conn, SpiceChannel *channel, int id,gint monitor_id)

{

//注释掉的地方   就是隐藏菜单、工具栏和状态栏

   gtk_container_set_border_width(GTK_CONTAINER(vbox), 0);

   gtk_container_add(GTK_CONTAINER(win->toplevel), vbox);

   //gtk_box_pack_start(GTK_BOX(vbox), win->menubar, FALSE, FALSE, 0);zy

   //gtk_box_pack_start(GTK_BOX(vbox), win->toolbar, FALSE, FALSE, 0);zy

   gtk_box_pack_start(GTK_BOX(vbox), win->spice, TRUE, TRUE, 0);

   //gtk_box_pack_end(GTK_BOX(vbox), win->statusbar, FALSE, TRUE, 0);zy

   /* show window */

   if (fullscreen)

         {//zy  修改fullscreen 的功能,使其变成左屏显示(什么都不加为右屏显示)

         //printf("fullscreen:%s\n",fullscreen);//zy

//       gtk_window_fullscreen(GTK_WINDOW(win->toplevel));zy

         gtk_window_set_default_size(GTK_WINDOW(win->toplevel),1000,600);//zy 设置窗口大小

         gtk_window_set_decorated(GTK_WINDOW(win->toplevel),FALSE);// add---zy

         gtk_window_move(GTK_WINDOW(win->toplevel),0,0);// add---zy 设置窗口起始位置

         }//zy

    Else  //右屏显示

         {

         gtk_window_set_default_size(GTK_WINDOW(win->toplevel),1000,600);//zy

         gtk_window_set_decorated(GTK_WINDOW(win->toplevel),FALSE);// add---zy

         gtk_window_move(GTK_WINDOW(win->toplevel),100,100);// add---zy

         }

}

static void menu_cb_select_usb_devices(GtkAction*action, void *data)

{

   gtk_box_set_spacing(GTK_BOX(gtk_bin_get_child(GTK_BIN(dialog))), 12);

   area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));

   usb_device_widget = spice_usb_device_widget_new(win->conn->session,

                                                   NULL,fullscreen); /* default format */ //zy 加入一个bool型的参数

   g_signal_connect(usb_device_widget, "connect-failed",

                    G_CALLBACK(usb_connect_failed), NULL);

   gtk_box_pack_start(GTK_BOX(area), usb_device_widget, TRUE, TRUE, 0);

}

static void display_monitors(SpiceChannel*display, GParamSpec *pspec,

                             spice_connection*conn)

{

w = create_spice_window(conn, display, id,i);

           add_window(conn, w);

           spice_g_signal_connect_object(display, "display-mark",

                                         G_CALLBACK(display_mark), w, 0);

           gtk_widget_show(w->toplevel);

                 menu_cb_select_usb_devices(NULL,(void*)w);   //zy-add  调用函数,自动实现窗口菜单栏的点击消息发送

           update_auto_usbredir_sensitive(conn);

}

usb-device-widget.h

修改函数声明

GtkWidget*spice_usb_device_widget_new(SpiceSession   *session,

                                       constgchar     *device_format_string,

                                            gboolean fullscreen);//zy

usb-device-widget.c

加入功能(将两套键盘鼠标的ID存在指定的文件里,以便窗口启动时根据ID绑定对应的设备)

static GObject*spice_usb_device_widget_constructor(

GType gtype,guint n_properties, GObjectConstructParam *properties)

{

//----------------------------add-----------------zy

   gchar *desc;

   char list_r[24]="";

   char list_l[24]="";

   int flag_mouse = 0;

   int flag_keyboard = 0;

   for (i = 0; i < devices->len; i++)

    {

       desc = spice_usb_device_get_description(g_ptr_array_index(devices, i),

                                           priv->device_format_string);

        char *token = strtok(desc," ");

        while(token != NULL)

          {

             if(strcmp(token,"Mouse") == 0 ||strcmp(token,"MOUSE") == 0)

                {

                   token = strtok(NULL,"");

                   if(flag_mouse == 0)

                    {

                        strcat(list_r,token);

                        flag_mouse++;

                    }

                    else

                    {

                        strcat(list_l,token);

                    }

                }

            if(strcmp(token,"Keyboard") == 0 ||strcmp(token,"KEYBOARD") == 0)

                {

                   token = strtok(NULL,"");

                   if(flag_keyboard == 0)

                    {

                        strcat(list_r,token);

                        flag_keyboard++;

                    }

                    else

                    {

                        strcat(list_l,token);

                    }

                 }

               token = strtok(NULL,"");

           }

    }

    g_free(desc);  //zy-add--

    FILE *fp;

    fp=fopen("/root/right.txt","w+");

    if(fp==NULL)return;

    fputs(list_r,fp);

    fclose(fp);

    fp=fopen("/root/left.txt","w+");

    if(fp==NULL)return;

    fputs(list_l,fp);

    fclose(fp);

//----------------------------end----------------

}

添加功能,程序读取配置文件信息,一次比较将usb设备绑定到虚拟机内

static voiddevice_added_cb(SpiceUsbDeviceManager *manager,

SpiceUsbDevice*device, gpointer user_data)

{

//----------------------------------add------------zy----------

   char str1[12];

   char str2[12];

   FILE *fp;

   if(flag_r_screen)

    {

   fp = fopen("/root/right.txt","r+");

   if(fp == NULL) return;

    }

   else

    {

   fp = fopen("/root/left.txt","r+");

   if(fp == NULL) return;

    }

   fgets(str1,12,fp);

   fgets(str2,12,fp);

   fclose(fp);

   printf("%s\n",str1);

   printf("%s\n",str2);

   g_print(_("zy5_1_description:%s\n"),desc);

   char *token = strtok(desc," ");

   while(token != NULL)

     {

       if(strcmp(token,str1) == 0 || strcmp(token,str2) == 0)

         {

            checkbox_clicked_cb(check,self);

         }

       token = strtok(NULL," ");

     }

   g_free(desc);

//---------------------------------end-------------------

}

修改点击事件处理函数,屏蔽掉状态的筛选,直接将传过来的设备添加到虚拟机中

static void checkbox_clicked_cb(GtkWidget*check, gpointer user_data)

{

/*  zy---del

   if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check))) {

       connect_cb_data *data = g_new(connect_cb_data, 1);

       data->check = g_object_ref(check);

       data->self  =g_object_ref(self);

       spice_usb_device_manager_connect_device_async(priv->manager,

                                                     device,

                                                     NULL,

                                                     connect_cb,

                                                     data);

    }else {

       spice_usb_device_manager_disconnect_device(priv->manager,

                                                  device);

    }

   spice_usb_device_widget_update_status(self);

*/

///---------------------add----------------zy

       connect_cb_data *data = g_new(connect_cb_data, 1);

       data->check = g_object_ref(check);

       data->self  =g_object_ref(self);

       spice_usb_device_manager_connect_device_async(priv->manager,

                                                     device,

                                                     NULL,

                                                     connect_cb,

                                                     data);

//------------------------end----------------------zy------

}

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
皕杰报表之UUID
​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为
待兔 待兔
5个月前
手写Java HashMap源码
HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22
Jacquelyn38 Jacquelyn38
3年前
2020年前端实用代码段,为你的工作保驾护航
有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )
Stella981 Stella981
3年前
KVM调整cpu和内存
一.修改kvm虚拟机的配置1、virsheditcentos7找到“memory”和“vcpu”标签,将<namecentos7</name<uuid2220a6d1a36a4fbb8523e078b3dfe795</uuid
Wesley13 Wesley13
3年前
mysql设置时区
mysql设置时区mysql\_query("SETtime\_zone'8:00'")ordie('时区设置失败,请联系管理员!');中国在东8区所以加8方法二:selectcount(user\_id)asdevice,CONVERT\_TZ(FROM\_UNIXTIME(reg\_time),'08:00','0
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Stella981 Stella981
3年前
Django中Admin中的一些参数配置
设置在列表中显示的字段,id为django模型默认的主键list_display('id','name','sex','profession','email','qq','phone','status','create_time')设置在列表可编辑字段list_editable
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
11个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这