我一直在将我的系统移植到 X11,但我在复制剪贴板时遇到了问题(粘贴已经可以了)。我关注了this .过了一会儿,我注意到他的例子也不起作用。问题是当我尝试将它粘贴到某个地方时,而不是 XA_STRING 请求的原子 ID 是 434。我找不到这个原子的用途。当我将 XA_STRING 更改为 434 时,出现了不同的错误。以下是代码。
void SetClipboardText(const std::string &text) {
XSetSelectionOwner (display, XA_CLIPBOARD, windowhandle, CurrentTime);
copiedtext=text;
XFlush(display);
std::cout<<"COPIED"<<std::endl;
}
...
case SelectionRequest:
XEvent respond;
std::cout<<"SELTYPE: "<<event.xselectionrequest.target<<std::endl;
if(event.xselectionrequest.target==XA_STRING &&
event.xselectionrequest.selection==XA_CLIPBOARD) {
std::cout<<"REQUESTED"<<std::endl;
XChangeProperty (display,
event.xselectionrequest.requestor,
event.xselectionrequest.property,
XA_STRING,
copiedtext.length(),
PropModeReplace,
(unsigned char*) copiedtext.c_str(),
copiedtext.length()
);
respond.xselection.property=event.xselectionrequest.property;
}
else {
respond.xselection.property= None;
}
respond.xselection.type= SelectionNotify;
respond.xselection.display= event.xselectionrequest.display;
respond.xselection.requestor= event.xselectionrequest.requestor;
respond.xselection.selection=event.xselectionrequest.selection;
respond.xselection.target= event.xselectionrequest.target;
respond.xselection.time = event.xselectionrequest.time;
XSendEvent (display, event.xselectionrequest.requestor,0,0,&respond);
XFlush (display);
break;
我用 434 替换 XA_STRING 时出错:
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 18 (X_ChangeProperty)
Value in failed request: 0x4
Serial number of failed request: 33
Current serial number in output stream: 36
如果相关,我使用 KDE 4.8 并且 klipper 目前已关闭。
编辑:来自网站的示例。
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <assert.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
main()
{
Display *dpy = XOpenDisplay(NULL);
assert(dpy);
Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
200, 100, 0, 0, 0);
XSelectInput(dpy, w, StructureNotifyMask);
XMapWindow(dpy, w);
XSelectionRequestEvent *req;
XEvent e, respond;
for(;;) {
XNextEvent(dpy, &e);
if (e.type == MapNotify) break;
}
XFlush(dpy);
//
Atom a1, a2, a3, type;
XSelectInput(dpy, w, StructureNotifyMask+ExposureMask);
int format, result;
unsigned long len, bytes_left, dummy;
unsigned char *data;
Window Sown;
for (int ii = 0; ii < 50; ii++) {
XSetSelectionOwner (dpy, XA_PRIMARY, w, CurrentTime);
XFlush (dpy);
XNextEvent (dpy, &e);
if (e.type == SelectionRequest)
//
// Somebody wants our data
//
{
req=&(e.xselectionrequest);
printf ("Selection Request from Mr %i I am %i\n",
(int)e.xselection.requestor, (int)w);
printf ("prop:%i tar:%i sel:%i\n", req->property,
req->target, req->selection);
if (req->target == XA_STRING)
{
XChangeProperty (dpy,
req->requestor,
req->property,
XA_STRING,
8,
PropModeReplace,
(unsigned char*) "It Works",
8);
respond.xselection.property=req->property;
}
else // Strings only please
{
printf ("No String %i\n",
(int)req->target);
respond.xselection.property= None;
}
respond.xselection.type= SelectionNotify;
respond.xselection.display= req->display;
respond.xselection.requestor= req->requestor;
respond.xselection.selection=req->selection;
respond.xselection.target= req->target;
respond.xselection.time = req->time;
XSendEvent (dpy, req->requestor,0,0,&respond);
XFlush (dpy);
}
}
}
编译使用
gcc copytest.c -o copytest -std=c99 -lX11
最佳答案
KDE 应用程序需要以下内容
else if(event.xselectionrequest.target==XA_TARGETS &&
event.xselectionrequest.selection==XA_CLIPBOARD) {
Atom supported[]={XA_STRING};
XChangeProperty (display,
event.xselectionrequest.requestor,
event.xselectionrequest.property,
XA_TARGETS,
8,
PropModeReplace,
(unsigned char *)(&supported),
sizeof(supported)
);
}
关于c++ - 剪贴板选择传输不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10570315/
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
状态:我正在构建一个应用程序,其中需要一个可供用户选择颜色的字段,该字段将包含RGB颜色代码字符串。我已经测试了一个看起来很漂亮但效果不佳的。它是“挑剔的颜色”,并托管在此存储库中:https://github.com/Astorsoft/picky-color.在这里我打开一个关于它的一些问题的问题。问题:请建议我在Rails3应用程序中使用一些颜色选择器。 最佳答案 也许页面上的列表jQueryUIDevelopment:ColorPicker为您提供开箱即用的产品。原因是jQuery现在包含在Rails3应用程序中,因此使用基
如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:
我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我
我完全不是程序员,正在学习使用Ruby和Rails框架进行编程。我目前正在使用Ruby1.8.7和Rails3.0.3,但我想知道我是否应该升级到Ruby1.9,因为我真的没有任何升级的“遗留”成本。缺点是什么?我是否会遇到与普通gem的兼容性问题,或者甚至其他我不太了解甚至无法预料的问题? 最佳答案 你应该升级。不要坚持从1.8.7开始。如果您发现不支持1.9.2的gem,请避免使用它们(因为它们很可能不被维护)。如果您对gem是否兼容1.9.2有任何疑问,您可以在以下位置查看:http://www.railsplugins.or
我希望用户从一个模型的三个选项中选择一个。即我有一个模型视频,可以被评为正面/负面/未知目前我有三列bool值(pos/neg/unknown)。这是处理这种情况的最佳方式吗?为此,表单应该是什么样的?目前我有类似的东西但显然它允许多项选择,而我试图将它限制为只有一个..怎么办? 最佳答案 如果要使用字符串列,让我们说rating。然后在你的表单中:#...#...它只允许一个选择编辑完全相同但使用radio_button_tag: 关于ruby-on-rails-Rails单选按钮-模
我目前正在尝试学习RubyonRails和测试框架RSpec。assigns在此RSpec测试中做什么?describe"GETindex"doit"assignsallmymodelas@mymodel"domymodel=Factory(:mymodel)get:indexassigns(:mymodels).shouldeq([mymodel])endend 最佳答案 assigns只是检查您在Controller中设置的实例变量的值。这里检查@mymodels。 关于ruby-o
我的Rails应用程序中安装了carrierwave。但是,当用户上传多页pdf时,我只希望应用程序获取文档中的第一页并将其转换为jpeg。这可能吗?用什么命令?这是我的uploader。#encoding:utf-8classImageUploader[200,300]##defscale(width,height)##dosomething#end#Createdifferentversionsofyouruploadedfiles:version:thumbdoprocess:resize_to_fill=>[150,210]process:convert=>:jpgdefful
对于用户模型,我有一个过滤器来检查用户的预订状态,该状态由整数值(0、1或2)表示。UserActiveAdmin索引页上的过滤器是通过以下代码实现的:filter:booking_status,as::select然而,这会导致下拉选项为0、1或2。当管理员用户从下拉列表中选择它们时,我更愿意自己将它们命名为“未完成”、“待定”和“已确认”之类的名称。有没有办法在不改变booking_status在模型中的表示方式的情况下做到这一点? 最佳答案 假设booking_status是模型中的枚举字段,您可以使用:过滤器:booking