My main experience is with C && C++, so I'd prefer to remain with them. I don't want to use anything like QT, GTK, or wxWidgets or any tool kits. I'd like to learn native programming and this sort of defeats the purpose. With that in mind I'd also like to avoid Java.
我在C && && c++的主要经验,所以我更愿意和他们呆在一起。我不想使用QT、GTK、wxWidgets或任何工具包。我想学习原生程序设计,但这种方法没有达到目的。考虑到这一点,我还想避免使用Java。
I understand gnome and xfce and KDE and such are all Desktop Environments for Linux, and the base installed typically is X (Xorg). When coding for Linux, do you code for X, or for the desktop environment? Is there a standard Linux header for this (like win32 has windows.h) for Linux? or is it different coding methods for every desktop environment?
我知道gnome、xfce和KDE等都是Linux的桌面环境,安装的基础通常是X (Xorg)。在为Linux编码时,您是为X编码,还是为桌面环境编码?是否有一个标准的Linux头文件(比如win32有windows.h)用于Linux?还是每个桌面环境都有不同的编码方法?
any help is greatly appreciated.
非常感谢您的帮助。
11 个解决方案
#1
65
X is a hideous layer to program for and, despite your intent to avoid Java, QT or any of the excellent UI abstraction layers, you'll be doing yourself a disservice by coding to that level. I've done it (a long time ago when Motif was in its infancy on the platform we were using) and I would not do it again if there was an easier way.
X是一个可怕的层,可以为它编程,尽管您有意避免Java、QT或任何优秀的UI抽象层,但您将通过将代码编码到这个级别来为自己服务。我已经这样做了(很久以前,Motif在我们使用的平台上还处于起步阶段),如果有更简单的方法,我不会再这样做了。
Your use of the phrase "native programming" confuses me a little. If you want to learn native programming, it's to the APIs that you choose to call. Using similar reasoning, you shouldn't be coding in C either, instead opting for assembler (or direct machine code) since C provides an abstraction to the hardware.
你对“本机编程”一词的使用让我有点困惑。如果你想学习本机编程,你需要选择调用的api。使用类似的推理,您也不应该使用C编写代码,而是选择汇编程序(或直接使用机器代码),因为C提供了对硬件的抽象。
If you want to learn X programming, that's fine. You'll end up with a lot more control over your interface but almost everyone else will be out-performing you in terms of delivery of software. Myself, I'd prefer to code to a higher-level API that I can use on many platforms - it gives me both faster delivery times and more market potential.
如果你想学X编程,没问题。你最终会对你的界面有更多的控制,但几乎所有人都会在软件交付方面胜过你。就我个人而言,我更喜欢代码,而不是更高级的API,我可以在许多平台上使用它——它提供了更快的交付时间和更大的市场潜力。
You don't build a house out of atoms, you build it out of bricks. My suggestion is to use the tools, that's what they're there for.
你不是用原子建造房子,而是用砖块建造。我的建议是使用这些工具,这就是它们的用途。
#2
44
I don't want to use anything like QT, GTK, or wxWidgets or any tool kits. I'd like to learn native programming and this sort of defeats the purpose.
我不想使用QT、GTK、wxWidgets或任何工具包。我想学习原生程序设计,但这种方法没有达到目的。
No you don't. Back in an early version of X11, like R1 or R2, I coded a complete "Hello, world" program in Xlib alone.
不,你没有。回到X11的早期版本,比如R1或R2,我单独在Xlib中编写了一个完整的“Hello, world”程序。
Roughly 700 lines of C.
大约700行C。
You don't want to go there.
你不想去那里。
#3
13
I guess you could write C code directly against Xlib, but you'd end up recreating all the functionality that GTK+ or QT provide that X doesn't alone.
我猜您可以直接针对Xlib编写C代码,但您最终将重新创建GTK+或QT提供的所有功能,而X并不单独提供这些功能。
#4
10
Unix (and by extension, Linux) doesn't actually define anything to do with GUIs. X, which is commonly used, doesn't define anything to do with widgets or styles or anything of that nature - it's concerned mostly with drawing primitives and event handling. Essentially, if you wanted to write in pure X, you'd be defining the shape and behaviour of every element on screen. If you were crazy enough to abandon X, you'd be working at the graphics framebuffer level...
Unix(扩展名为Linux)实际上并没有定义与gui相关的任何东西。通常使用的X不定义任何与窗口小部件或样式或任何类似性质的东西——它主要关注的是绘制基本类型和事件处理。本质上,如果你想写纯X,你需要定义屏幕上每个元素的形状和行为。如果你疯狂到放弃X,你将在图形框架层工作……
You're better off using some toolkit - if you're looking for light-weight, why not try FLTK?
你最好使用一些工具包——如果你想找轻一点的,为什么不试试FLTK呢?
#5
4
GTK, QT and wx are toolkits that build on X to provide a friendlier API.
GTK、QT和wx是构建在X上的工具包,可以提供更友好的API。
If you don't use an existing toolkit you'll need to write things at a very low level - directly handling mouse and keyboard events. If you want a button or a textbox you'll have to write it yourself using the low level xlib primitives.
如果您不使用现有的工具包,您将需要在非常低的级别上编写东西——直接处理鼠标和键盘事件。如果您想要一个按钮或一个文本框,您必须自己使用低级的xlib原语编写它。
Before trying this you're probably better off picking the toolkit of your preferred desktop environment and starting with that.
在尝试这之前,您最好选择首选桌面环境的工具包,并从它开始。
#6
4
There is simply no such thing as "native" in this case. Windows and OS X just have an official option, while X does not.
在这种情况下根本不存在所谓的“本土”。Windows和OS X只有一个官方选项,而X没有。
#7
3
The "native" interface for Linux & most other Unix-like OSs is Xlib, the lowest-level C API for X11.
Linux的“本机”接口和大多数其他类unix的OSs是Xlib, X11的最低级别C API。
GTK, Qt & others are all (so far as I know) implemented in terms of Xlib at their core. As others have said, Xlib gives you maximal control but you'll have to work for it (and others may run circles around you in terms of delivering a product).
GTK、Qt和其他所有的(据我所知)都是用Xlib实现的。就像其他人说的,Xlib会给你最大的控制,但是你必须为它工作(其他人可能会在你提*品的时候围着你转)。
As a point of reference, I personally implemented a fairly feature-rich & modern (i.e. flowable) cross-platform (Win32 + X11) GUI library in C++. Total count is about 29 KLOC of C++, of which about 2500 lines each was required for the X11 & Win32 shimming. The rest is for platform-neutral Widget implementations. Unless you're prepared to make a commitment like that, I strongly recommend going with one of the higher level libraries (Qt would probably be my choice, though I can't stand the preprocessor approach).
作为参考,我个人在c++中实现了一个功能丰富、现代的(即可流动的)跨平台(Win32 + X11) GUI库。总数量约为29 KLOC的c++,其中大约2500行是X11和Win32 shimming所需要的。其余部分用于与平台无关的小部件实现。除非您准备做出这样的承诺,否则我强烈建议您使用更高级别的库(Qt可能是我的选择,尽管我无法忍受预处理器方法)。
BTW, a big plus for Xlib is its raw portability--any Unix box with a screen will have it, and it can be made to work on Windows & OS X as well.
顺便说一句,Xlib的一大优点是它的原始可移植性——任何带屏幕的Unix盒子都有它,而且它还可以在Windows和OS X上使用。
#8
2
I feel it necessary to counterpoint the unanimity of the other answers here. X11 is indeed low level. But to "truly" understand what's going on, you should have some familiarity with how X11 works. Since all the toolkits work on top of X, you're using it whether you like it or not. There is nice tutorial online somewhere that I'm too lazy to search for. It guides you through building a simple Hello World. To do it, you'll have to learn how to create a window, request events, map the window, and process events in a loop. You could even go so far as to order some used books on Amazon. The O'Reilly vols 1 and 2 (for now get the cheapest editions, but nothing earlier than X11R4) are essential for reference and to get the full story of how the pieces work together. For learning, however, the best book is X Window Applications Programming by Eric Johnson and Kevin Reichard.
我觉得有必要反驳这里其他答案的一致。X11确实很低。但是要“真正”理解发生了什么,您应该对X11的工作方式有一些了解。因为所有的工具包都在X的上面工作,所以不管你喜欢与否,你都在使用它。网上有很好的教程,我懒得去找。它指导您构建一个简单的Hello World。为此,您必须学习如何在循环中创建窗口、请求事件、映射窗口和处理事件。你甚至可以在亚马逊上订购一些二手书。O'Reilly vols 1和2(目前得到最便宜的版本,但没有比X11R4更早的版本)对于参考和了解各个部分如何工作的完整故事是必不可少的。然而,对于学习来说,最好的书是Eric Johnson和Kevin Reichard编写的X Window Applications。
At some point along this journey, as everyone else says, you will find you've had enough. Two pages of code just to select a visual, and then you still have to populate a colormap before you can paint your custom bitmap. And then two days of rewriting and debugging to realize that it all does work; you just forgot to XFlush()
!
在这段旅程的某个时刻,正如其他人所说,你会发现你已经受够了。两页的代码只是为了选择一个可视的,然后您仍然需要填充一个colormap,然后才能绘制您的自定义位图。经过两天的重写和调试,我发现这一切都是可行的;你只是忘了XFlush()!
The struggle is important, because you'll appreciate the toolkits more once you find the one you like.
斗争是很重要的,因为一旦你找到你喜欢的工具包,你会更喜欢它。
#9
1
I would suggest lesstif/motif as well. It also builds on top of X and the learning curve is, in my opinion, isn't as steep as GTK or Qt. The UI's you build with it aren't going to be as sophisticated as ones you could build with GTK or Qt though. More information can be found here.
我也建议减少主题。它也构建在X之上,在我看来,学习曲线并不像GTK或Qt那样陡峭。更多信息可以在这里找到。
As others have mentioned you probably don't want to X it's a pain.
正如其他人提到的,你可能不想要X,这是一种痛苦。
#10
0
Why not choose one among, say, Qt, wxWidgets and GTK and learn its internals, rather than its API? I do not mean just for the sake of it, but with the aim of contributing to the parts you find most appealing. In this way you'd fulfill your goal and get to do something useful, for you and also for others. I think this would be more rewarding than assigning yourself the rather artificial task of building an application with what amount to the wrong tools.
为什么不从Qt、wxWidgets和GTK中选择一个,学习它的内部特性,而不是它的API呢?我的意思不是仅仅为了它,而是为了帮助你找到最吸引人的部分。这样你就能实现你的目标,并为你和他人做一些有用的事情。我认为这比给自己分配一个人工任务来构建一个应用程序的错误工具更有意义。
#11
0
oh yeah, there is such "native" things:
哦,是啊,有这么一种“本土”的东西:
FBUI, svgalib, directfb, exa(kdrive), SDL, Allegro..+Wayland, although not mainstream.
FBUI, svgalib, directfb, exa(kdrive), SDL, Allegro。+韦兰,虽然不是主流。
http://home.comcast.net/~fbui/
http://home.comcast.net/ ~ fbui /
http://www.svgalib.org/
http://directfb.org/
http://xorg.freedesktop.org/wiki/ExaStatus
http://xorg.freedesktop.org/wiki/ExaStatus
+ http://wayland.freedesktop.org/
+ http://wayland.freedesktop.org/
#1
65
X is a hideous layer to program for and, despite your intent to avoid Java, QT or any of the excellent UI abstraction layers, you'll be doing yourself a disservice by coding to that level. I've done it (a long time ago when Motif was in its infancy on the platform we were using) and I would not do it again if there was an easier way.
X是一个可怕的层,可以为它编程,尽管您有意避免Java、QT或任何优秀的UI抽象层,但您将通过将代码编码到这个级别来为自己服务。我已经这样做了(很久以前,Motif在我们使用的平台上还处于起步阶段),如果有更简单的方法,我不会再这样做了。
Your use of the phrase "native programming" confuses me a little. If you want to learn native programming, it's to the APIs that you choose to call. Using similar reasoning, you shouldn't be coding in C either, instead opting for assembler (or direct machine code) since C provides an abstraction to the hardware.
你对“本机编程”一词的使用让我有点困惑。如果你想学习本机编程,你需要选择调用的api。使用类似的推理,您也不应该使用C编写代码,而是选择汇编程序(或直接使用机器代码),因为C提供了对硬件的抽象。
If you want to learn X programming, that's fine. You'll end up with a lot more control over your interface but almost everyone else will be out-performing you in terms of delivery of software. Myself, I'd prefer to code to a higher-level API that I can use on many platforms - it gives me both faster delivery times and more market potential.
如果你想学X编程,没问题。你最终会对你的界面有更多的控制,但几乎所有人都会在软件交付方面胜过你。就我个人而言,我更喜欢代码,而不是更高级的API,我可以在许多平台上使用它——它提供了更快的交付时间和更大的市场潜力。
You don't build a house out of atoms, you build it out of bricks. My suggestion is to use the tools, that's what they're there for.
你不是用原子建造房子,而是用砖块建造。我的建议是使用这些工具,这就是它们的用途。
#2
44
I don't want to use anything like QT, GTK, or wxWidgets or any tool kits. I'd like to learn native programming and this sort of defeats the purpose.
我不想使用QT、GTK、wxWidgets或任何工具包。我想学习原生程序设计,但这种方法没有达到目的。
No you don't. Back in an early version of X11, like R1 or R2, I coded a complete "Hello, world" program in Xlib alone.
不,你没有。回到X11的早期版本,比如R1或R2,我单独在Xlib中编写了一个完整的“Hello, world”程序。
Roughly 700 lines of C.
大约700行C。
You don't want to go there.
你不想去那里。
#3
13
I guess you could write C code directly against Xlib, but you'd end up recreating all the functionality that GTK+ or QT provide that X doesn't alone.
我猜您可以直接针对Xlib编写C代码,但您最终将重新创建GTK+或QT提供的所有功能,而X并不单独提供这些功能。
#4
10
Unix (and by extension, Linux) doesn't actually define anything to do with GUIs. X, which is commonly used, doesn't define anything to do with widgets or styles or anything of that nature - it's concerned mostly with drawing primitives and event handling. Essentially, if you wanted to write in pure X, you'd be defining the shape and behaviour of every element on screen. If you were crazy enough to abandon X, you'd be working at the graphics framebuffer level...
Unix(扩展名为Linux)实际上并没有定义与gui相关的任何东西。通常使用的X不定义任何与窗口小部件或样式或任何类似性质的东西——它主要关注的是绘制基本类型和事件处理。本质上,如果你想写纯X,你需要定义屏幕上每个元素的形状和行为。如果你疯狂到放弃X,你将在图形框架层工作……
You're better off using some toolkit - if you're looking for light-weight, why not try FLTK?
你最好使用一些工具包——如果你想找轻一点的,为什么不试试FLTK呢?
#5
4
GTK, QT and wx are toolkits that build on X to provide a friendlier API.
GTK、QT和wx是构建在X上的工具包,可以提供更友好的API。
If you don't use an existing toolkit you'll need to write things at a very low level - directly handling mouse and keyboard events. If you want a button or a textbox you'll have to write it yourself using the low level xlib primitives.
如果您不使用现有的工具包,您将需要在非常低的级别上编写东西——直接处理鼠标和键盘事件。如果您想要一个按钮或一个文本框,您必须自己使用低级的xlib原语编写它。
Before trying this you're probably better off picking the toolkit of your preferred desktop environment and starting with that.
在尝试这之前,您最好选择首选桌面环境的工具包,并从它开始。
#6
4
There is simply no such thing as "native" in this case. Windows and OS X just have an official option, while X does not.
在这种情况下根本不存在所谓的“本土”。Windows和OS X只有一个官方选项,而X没有。
#7
3
The "native" interface for Linux & most other Unix-like OSs is Xlib, the lowest-level C API for X11.
Linux的“本机”接口和大多数其他类unix的OSs是Xlib, X11的最低级别C API。
GTK, Qt & others are all (so far as I know) implemented in terms of Xlib at their core. As others have said, Xlib gives you maximal control but you'll have to work for it (and others may run circles around you in terms of delivering a product).
GTK、Qt和其他所有的(据我所知)都是用Xlib实现的。就像其他人说的,Xlib会给你最大的控制,但是你必须为它工作(其他人可能会在你提*品的时候围着你转)。
As a point of reference, I personally implemented a fairly feature-rich & modern (i.e. flowable) cross-platform (Win32 + X11) GUI library in C++. Total count is about 29 KLOC of C++, of which about 2500 lines each was required for the X11 & Win32 shimming. The rest is for platform-neutral Widget implementations. Unless you're prepared to make a commitment like that, I strongly recommend going with one of the higher level libraries (Qt would probably be my choice, though I can't stand the preprocessor approach).
作为参考,我个人在c++中实现了一个功能丰富、现代的(即可流动的)跨平台(Win32 + X11) GUI库。总数量约为29 KLOC的c++,其中大约2500行是X11和Win32 shimming所需要的。其余部分用于与平台无关的小部件实现。除非您准备做出这样的承诺,否则我强烈建议您使用更高级别的库(Qt可能是我的选择,尽管我无法忍受预处理器方法)。
BTW, a big plus for Xlib is its raw portability--any Unix box with a screen will have it, and it can be made to work on Windows & OS X as well.
顺便说一句,Xlib的一大优点是它的原始可移植性——任何带屏幕的Unix盒子都有它,而且它还可以在Windows和OS X上使用。
#8
2
I feel it necessary to counterpoint the unanimity of the other answers here. X11 is indeed low level. But to "truly" understand what's going on, you should have some familiarity with how X11 works. Since all the toolkits work on top of X, you're using it whether you like it or not. There is nice tutorial online somewhere that I'm too lazy to search for. It guides you through building a simple Hello World. To do it, you'll have to learn how to create a window, request events, map the window, and process events in a loop. You could even go so far as to order some used books on Amazon. The O'Reilly vols 1 and 2 (for now get the cheapest editions, but nothing earlier than X11R4) are essential for reference and to get the full story of how the pieces work together. For learning, however, the best book is X Window Applications Programming by Eric Johnson and Kevin Reichard.
我觉得有必要反驳这里其他答案的一致。X11确实很低。但是要“真正”理解发生了什么,您应该对X11的工作方式有一些了解。因为所有的工具包都在X的上面工作,所以不管你喜欢与否,你都在使用它。网上有很好的教程,我懒得去找。它指导您构建一个简单的Hello World。为此,您必须学习如何在循环中创建窗口、请求事件、映射窗口和处理事件。你甚至可以在亚马逊上订购一些二手书。O'Reilly vols 1和2(目前得到最便宜的版本,但没有比X11R4更早的版本)对于参考和了解各个部分如何工作的完整故事是必不可少的。然而,对于学习来说,最好的书是Eric Johnson和Kevin Reichard编写的X Window Applications。
At some point along this journey, as everyone else says, you will find you've had enough. Two pages of code just to select a visual, and then you still have to populate a colormap before you can paint your custom bitmap. And then two days of rewriting and debugging to realize that it all does work; you just forgot to XFlush()
!
在这段旅程的某个时刻,正如其他人所说,你会发现你已经受够了。两页的代码只是为了选择一个可视的,然后您仍然需要填充一个colormap,然后才能绘制您的自定义位图。经过两天的重写和调试,我发现这一切都是可行的;你只是忘了XFlush()!
The struggle is important, because you'll appreciate the toolkits more once you find the one you like.
斗争是很重要的,因为一旦你找到你喜欢的工具包,你会更喜欢它。
#9
1
I would suggest lesstif/motif as well. It also builds on top of X and the learning curve is, in my opinion, isn't as steep as GTK or Qt. The UI's you build with it aren't going to be as sophisticated as ones you could build with GTK or Qt though. More information can be found here.
我也建议减少主题。它也构建在X之上,在我看来,学习曲线并不像GTK或Qt那样陡峭。更多信息可以在这里找到。
As others have mentioned you probably don't want to X it's a pain.
正如其他人提到的,你可能不想要X,这是一种痛苦。
#10
0
Why not choose one among, say, Qt, wxWidgets and GTK and learn its internals, rather than its API? I do not mean just for the sake of it, but with the aim of contributing to the parts you find most appealing. In this way you'd fulfill your goal and get to do something useful, for you and also for others. I think this would be more rewarding than assigning yourself the rather artificial task of building an application with what amount to the wrong tools.
为什么不从Qt、wxWidgets和GTK中选择一个,学习它的内部特性,而不是它的API呢?我的意思不是仅仅为了它,而是为了帮助你找到最吸引人的部分。这样你就能实现你的目标,并为你和他人做一些有用的事情。我认为这比给自己分配一个人工任务来构建一个应用程序的错误工具更有意义。
#11
0
oh yeah, there is such "native" things:
哦,是啊,有这么一种“本土”的东西:
FBUI, svgalib, directfb, exa(kdrive), SDL, Allegro..+Wayland, although not mainstream.
FBUI, svgalib, directfb, exa(kdrive), SDL, Allegro。+韦兰,虽然不是主流。
http://home.comcast.net/~fbui/
http://home.comcast.net/ ~ fbui /
http://www.svgalib.org/
http://directfb.org/
http://xorg.freedesktop.org/wiki/ExaStatus
http://xorg.freedesktop.org/wiki/ExaStatus
+ http://wayland.freedesktop.org/
+ http://wayland.freedesktop.org/