Spicy 修改代码 实现双屏显示以及鼠标键盘绑定
Posted 乌托邦2号
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spicy 修改代码 实现双屏显示以及鼠标键盘绑定相关的知识,希望对你有一定的参考价值。
修改 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------
————————————————
版权声明:本文为CSDN博主「傻呆」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_21398167/article/details/50804271
以上是关于Spicy 修改代码 实现双屏显示以及鼠标键盘绑定的主要内容,如果未能解决你的问题,请参考以下文章
使用delphi多线程实现绑定某个EXE的进程并且向它发送键盘鼠标消息的实例。