Cursor do linux no windows

How to load windows cursors (.cur) in Linux using XLib and Xcursors?

Any obvious error? I can’t really find sources about Xcursor and i’m close to switch to typical OpenGL textures and get over it. NOTE: I’m already disabled Virtualbox integrated mouse, so the mouse is entirely on guest machine and i run it fullscreen.

@Leiaz, thank you for the comment. I assume the cursor you tested with is .xbm (x window bitmap) ? From documentation here i can’t really find out if Xcursor supports .cur or not. Thank you for the effort.

Oh .. that is probably the problem. file says it’s a «X11 cursor». .cur seems to be a Windows format. The Xcursor file format is defined in the man page, I don’t think it’s possible to use another format directly. There is a xcursorgen utility to create a Xcursor from PNG file(s).

@Leiaz, thank you. I had the impression .cur are compatible with Xcursor, but they’re not. Even .xbm or .xpm were not loaded. Your cursors loaded as well 🙂 although i can’t find out what they are or how to create them (i mean, specs) The only thing for sure their header start with Xcur.. . Convert PNGs to xcursor i don’t find it really good since i want to be able to use the same cursor in Windows/Linux and don’t like really to provide hotspots as well; perhaps some internal conversion from .cur to xcurso` might be the way once i find out the xcursor format. I’ll post my results.

There was a problem in Oracle Virtualbox not able to show hardware cursors on OpenGL context ; they’ve shown under it and this is known issue (as i learnt) for quite some time now. This gave the impression of cursors-not-loaded. I just switched to VMware and it doesn’t suffering from this.

1 Answer 1

Since i solved my problem i decided it’s a good idea to post my results, in hope of helping someone trying to make his application more cross-platform. My code follows, and explanation follows the code.

  • X11 development headers package (etc. libx11-dev)
  • Xcursor development headers package (etc. libxcursor-dev)
  • A portable header, like this one.
. // to store colors struct COLOR < uint8_t r,g,b,a; COLOR() < this->r = this->g = this->b = this->a = 0; > COLOR(uint8_t r,uint8_t g,uint8_t b) < this->r = r; this->g = g; this->b = b; this->a = 255; > bool operator == (COLOR c) const < return (r == c.r && g == c.g && b == c.b); >>; size_t get_bit(int32_t number,int8_t position) < size_t bitmask = 1 . // load cursor #if defined(_WIN32) // etc. use standard WinApi code, (HCURSOR)LoadImage(..) and such #endif #if defined(__linux__) Display* display = XOpenDisplay(NULL); string filename = "mycursor.cur"; // fread(buf,1,2,fp); // number of images // we're only interested in the first image fread(buf,1,1,fp); // width (0 to 255; 0=means 256 width) int8_t width = (buf[0]==0 ? 256 : buf[0]); fread(buf,1,1,fp); // height (0 to 255; 0=means 256 height) int8_t height = (buf[0]==0 ? 256 : buf[0]); fread(buf,1,1,fp); // number of colors in palette (0 for no palette) fread(buf,1,1,fp); // reserved. should be 0 fread(buf,1,2,fp); // hotspot x int16_t hotspot_x = buf[0] | (buf[1] <<8); fread(buf,1,2,fp); // hotspot y int16_t hotspot_y = buf[0] | (buf[1]<<8); fread(buf,1,4,fp); // image data in bytes fread(buf,1,4,fp); // offset to image data // Now we need to verify if image in .cur is BMP or PNG (Vista+) // We can't just check 'magic' since if it's BMP, the header will be missing (PNG is whole) // So we search for PNG magic; if doesnt exist, we have a BMP! // NOTE: for simplicity we go only for BMP for the moment. // So just check if 'biSize' is 40 (Windows NT & 3.1x or later) // BITMAPINFOHEADER fread(buf,1,4,fp); // biSize int32_t biSize = (buf[0]&0xff) | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24); if (biSize!=40) < // error: file does not contain valid BMP data; return; >fread(buf,1,4,fp); // biWidth int32_t biWidth = (buf[0]&0xff) | (buf[1] <<8) | (buf[2]<<16) | (buf[3]<<24); fread(buf,1,4,fp); // biHeight (if positive =>bottom-up, if negative => up-bottom) int32_t biHeight = (buf[0]&0xff) | (buf[1] <<8) | (buf[2]<<16) | (buf[3]<<24); fread(buf,1,2,fp); // biPlanes fread(buf,1,2,fp); // biBitCount int16_t biBitCount = (buf[0]&0xff) | (buf[1]<<8) | (buf[2]<<16) | (buf[3]<<24); if (biBitCount!=24 && biBitCount!=32) < // error: only 24/32 bits supported; return; >fread(buf,1,4,fp); // biCompression int32_t biCompression = (buf[0]&0xff) | (buf[1] <<8) | (buf[2]<<16) | (buf[3]<<24); // we want only uncompressed BMP data if (biCompression!=0 /*BI_RGB*/ ) < // error: file is compressed; only uncompressed BMP is supported; return; >fread(buf,1,4,fp); // biSizeImage fread(buf,1,4,fp); // biXPelsPerMeter fread(buf,1,4,fp); // biYPelsPerMeter fread(buf,1,4,fp); // biClrUsed fread(buf,1,4,fp); // biClrImportant // DECODE IMAGE uint8_t origin = (biHeight>0 ? 0 : 1); // 0=bottom-up, 1=up-bottom // there are cases where BMP sizes are NOT the same with cursor; we use the cursor ones biWidth = width; biHeight = height; COLOR* pixels = new COLOR[biWidth * biHeight]; for(int32_t y=0;y > > // read mask // mask is 1-bit-per-pixel for describing the cursor bitmap's opaque and transparent pixels. // so for 1 pixel we need 1 bit, for etc. 32 pixels width, we need 32*1 bits (or 4 bytes per line) // so for etc. 32 pixels height we need 4*32 = 128 bytes or [mask bytes per line * height] uint16_t mask_bytes_per_line = biWidth / 8; uint16_t mask_bytes = mask_bytes_per_line * biHeight; char* mask = new char[mask_bytes]; fread(mask,1,mask_bytes,fp); fclose(fp); // reverse every [mask_bytes_per_line] bytes; (etc. for 4 bytes per line do: 0,1,2,3 => 3,2,1,0) -> you really need to ask Microsoft for this 8) char rmask[4]; for(uint16_t x=0;x // copy the reversed line for(uint16_t r=0;r > // now extract all bits from mask bytes into new array (equal to width*height) vector bits; for(uint16_t x=0;x > delete[] mask; // reverse vector (?) reverse(bits.begin(),bits.end()); // now the bits contains =1 (transparent) and =0 (opaque) which we use on cursor directly XcursorImage* cimg = XcursorImageCreate(biWidth,biHeight); cimg->xhot = hotspot_x; cimg->yhot = hotspot_y; // create the image for(int32_t y=0;ypixels[offset] = ((bits[offset]==1?0:pix.a) <<24) + (pix.r<<16) + (pix.g<<8) + (pix.b); >> // create cursor from image and release the image Cursor cursor = XcursorImageLoadCursor(display,cimg); XcursorImageDestroy(cimg); . // set the cursor XDefineCursor(display,yourwindow,cursor); XFlush(display); . // free cursor if (cursor!=None)

The above code takes a Windows .cur cursor file and creates an Xcursor for use in X11 window system. Of course, there are lots of limitations to my .cur format handling but one can easily add his own improvements to the above code (like say supporting 8-bit cursors). The above code not only take care of alpha-transparency but also 32-bit alpha-blended cursors

Источник

Установить курсор Windows 8 в Ubuntu 13.04/12.10/12.04 и Linux Mint 14/13

Не так давно разработчиком David Farkas был создан курсор Windows 8 для Linux, который можно установить в Ubuntu/Linux Mint.

Установка курсора Windows 8

Прежде всего для установки курсора необходимо создать папку .icons (если ещё не создана), куда и будет размещена тема с курсором. Откройте терминал (Ctrl+Alt+T), скопируйте и выполните следующую команду:

Если после выполнения команды в терминале получите следующие сообщение:

Значит папка уже существует, скорее всего вы уже устанавливали флажки для раскладки клавиатуры или ещё какие-нибудь значки. Тогда преходим к следующему шагу.

Следующим шагом будет загрузка файла с темой курсора Windows 8 . Кликните на ссылку ниже для загрузки темы.

Click здесь (Windows 8 cursors 1.01)

И выполните так, как на снимке:

Далее его нужно распаковать/извлечь:

Извлечь его нужно по адресу: ~/.icons:

И на этом установка темы курсора Windows 8 закончена.

Для того чтобы курсор Windows 8 отображался во всех приложениях правильно, его нужно дописать в файл index.theme. Откройте файл в текстовом редакторе следующей командой:

gksu gedit /usr/share/icons/default/index.theme

И замените в нём единственную строку на следующую:

Должно получиться как на снимке:

Остаётся последний шаг, активация курсора Windows 8. Для этого откройте Ubuntu Tweak: Настройка ->Тема ->Тема указателя мыши и активируйте win8:

Источник

How to Change the Mouse Cursor in Ubuntu 22.04 / Fedora 36 Gnome Desktop

The default Gnome Desktop in Ubuntu has a few themes for the mouse pointer. They are either in dark, light, or other different color and layout. And this tutorial will help you how to change the cursor and/or install some more from the web.

Change Mouse Cursor in Gnome:

Since Ubuntu defaults to the Gnome Desktop, this method also works in other Linux, e.g, Fedora, Debian, CentOS, Red Hat Enterprise Linux, SUSE Linux Enterprise, etc.

Firstly, open the Software app. Search for and install the “Gnome Tweaks” tool, one of the must have configuration tool for managing the GNOME Desktop.

Once installed, search for and start GNOME Tweaks from the top-left ‘Activities‘ overview. When it opens, navigate to Appearance from left pane and choose another cursor from the drop-down box.

Install more Mouse Cursors for Ubuntu Linux:

As you see, there are only a few cursor themes available out-of-the-box. You can however install tons more from the web. And here are some of them:

1. Volantes Cursors

For classic cursor with a flying style, Volantes is a popular one in both dark and light. You can get it HERE.

2. Oreo Cursors

This is a color material cursors for Linux desktop with cute animation. It offers both 32 px and 64 px with hidpi display support. And the cursor is available in more than 10 different colors. Get Oreo Cursors.

3. Bibata

This is a modern Windows style cursor theme in three different colors. It supports HiDPi Display, and each theme has both round edges and sharp edges icons.

There are tons more other cursor themes, you can get them from the link below:

How to Install Mouse Cursor Themes:

Installing the cursors is easy in Linux. All you have to do the put the source folders into right place: “.icons” for current user only, or “/usr/share/icons” for all users in the system.

For beginners, it’s recommended to put cursor themes into .icons under user’s home directory. NOTE: It’s a hidden file folder, you need to open “Files” (nautilus file manager) and press Ctrl+H to show/hide them.

And .icons is not exist out-of-the-box, create the folder if you don’t find it. Then put the cursor theme folders into it. Each theme contains a “index.theme” file and “cursors” folder with pointer icons.

After installed them, open or re-open GNOME Tweaks and you’ll see the new choices in the drop-down box under Appearances pane.

Источник

Читайте также:  Windows xp или linux ubuntu
Оцените статью
Adblock
detector