X Window研究笔记(22)

news/2024/7/8 4:54:43
X Window研究笔记(22)

转载时请注明出处和作者联系方式
作者联系方式:李先静

22.X Window 简单示例

对大多数linux程序员来说,很少有机会直接用Xlib去开发应用程序,那样开发效率太低,一般都是使用基于像GTK+和QT这样的toolkit。不过了解一下
XWindow编程 没有什么坏处,这里举一个简单的例子,供新手参考:

xdemo.c

#include <string.h>
#include 
<X11/Xlib.h>
#include 
<X11/keysym.h>

int main(int argc, char* argv[])
{
    Display
* display = XOpenDisplay(NULL);
    
int screen = DefaultScreen(display);
    
int width = DisplayWidth(display, screen)/2;
    
int height = DisplayHeight(display, screen)/2;

    Window win 
= XCreateSimpleWindow(display, RootWindow(display, screen),
        
00, width, height, 3, BlackPixel(display, screen), WhitePixel(display, screen));

    XSelectInput(display, win, ExposureMask
|KeyPressMask | ButtonPressMask | StructureNotifyMask);

    GC gc 
= XCreateGC(display, win, 0, NULL);

    XMapWindow(display, win);

    
while(1)
    
{
        XEvent 
event = {0};
        XNextEvent(display, 
&event);
        
switch(event.type)
        
{
            
case ConfigureNotify:
            
{
                width 
= event.xconfigure.width;
                height 
= event.xconfigure.height;
                
break;
            }

            
case Expose:
            
{
                XSetForeground(display, gc, WhitePixel(display, screen));
                XFillRectangle(display, win, gc, 
00, width, height);
               XSetForeground(display, gc, BlackPixel(display, screen));
                XDrawString(display, win, gc, width
/2, height/2"XWindow"7);
                
break;
            }

            
case KeyPress:
            
{
                
if(event.xkey.keycode == XKeysymToKeycode(display, XK_Escape))
                
{
                    XFreeGC(display, gc);
                    XCloseDisplay(display);
                    
return 0;
                }

            }

            
default:break;
        }

    }


    
return 0;
}

   

 Makefile
all:
    gcc 
--lX11 xdemo.-o xdemo
clean
:
    rm 
-f xdemo

(我并不擅长X Window编程,请不要问我关于X Window编程的问题。)

~~end~~




http://www.niftyadmin.cn/n/3648126.html

相关文章

discord china_如何在Ubuntu 18.04上使用Discord Webhooks获取有关您的网站状态的通知

discord chinaThe author selected the Apache Software Foundation to receive a donation as part of the Write for DOnations program. 作者选择了Apache Software Foundation作为Write for DOnations计划的一部分来接受捐赠。 介绍 (Introduction) When you have critica…

Java中transient关键字

Java中transient关键字1.只要这个类实现了Serilizable接口&#xff0c;这个类的所有属性和方法都会自动序列化。 2.如果在实现了Serilizable接口的类中&#xff0c;对该类的某属性添加transient关键字&#xff0c;那么在序列化对象的时候&#xff0c;这个属性就不会被序列化。…

蓝牙协议读书笔记

蓝牙协议读书笔记转载时请注明出处和作者联系方式作者联系方式&#xff1a;李先静 昨天翻了一下Multimedia.Wireless.Networks.Technologies.Standards.and.QoS&#xff0c;看了其中的bluetooth一章&#xff0c;虽然还有很多细节没有搞明白&#xff0c;不过基本框架还是清楚了&…

如何在Ubuntu 20.04上使用Postgres,Nginx和Gunicorn设置Django

介绍 (Introduction) Django is a powerful web framework that can help you get your Python application or website off the ground. Django includes a simplified development server for testing your code locally, but for anything even slightly production related…

linux蓝牙驱动代码阅读笔记

linux蓝牙驱动代码阅读笔记转载时请注明出处和作者联系方式作者联系方式&#xff1a;李先静 昨天看了一下介绍蓝牙协议文档&#xff0c;今天索性对照看了看kernel里的代码(bluez)&#xff0c;这里记点笔记&#xff0c;还是继承了老毛病&#xff0c;只关注整体流程而忽略细节&am…

acme.sh 更换dns_如何在Ubuntu 18.04上使用acme-dns-certbot使用DNS验证来获取让我们加密证书

acme.sh 更换dnsThe author selected the COVID-19 Relief Fund to receive a donation as part of the Write for DOnations program. 作者选择了COVID-19救济基金来接受捐赠&#xff0c;这是Write for DOnations计划的一部分。 介绍 (Introduction) The majority of Let’s …

如何应对HashMap线程不安全的问题?

1、使用Hashtable替代HashMap 当一个线程访问HashTable的同步方法时&#xff0c;其他线程如果也要访问同步方法&#xff0c;会被阻塞住。举个例子&#xff0c;当一个线程使用put方法时&#xff0c;另一个线程不但不可以使用put方法&#xff0c;连get方法都不可以。效率很低&…

音频处理介绍(Linux手机)

音频处理介绍(Linux手机)转载时请注明出处和作者联系方式作者联系方式&#xff1a;李先静 昨天从整体上介绍了一下音频处理流程&#xff0c;让大家对音频处理有个大致的概念&#xff0c;以便进行深入的研究。整个音频处理可以分为三个部分&#xff1a;用户空间Mplayerservice 它…