Skip to content

Commit

Permalink
Fix X11 app icon
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Dec 6, 2017
1 parent 9378379 commit 31bf851
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 49 deletions.
7 changes: 1 addition & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,9 @@ if(WIN32)
main/settings.manifest)
endif()

if(UNIX AND NOT APPLE AND USE_ALLEG4_BACKEND)
set(x11_resources main/xpm_icon.c)
endif()

add_executable(aseprite WIN32
main/main.cpp
${win32_resources}
${x11_resources})
${win32_resources})
target_link_libraries(aseprite app-lib ${PLATFORM_LIBS})
add_dependencies(aseprite copy_data)

Expand Down
28 changes: 28 additions & 0 deletions src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@
#include "base/unique_ptr.h"
#include "doc/site.h"
#include "doc/sprite.h"
#include "fmt/format.h"
#include "render/render.h"
#include "she/display.h"
#include "she/error.h"
#include "she/surface.h"
#include "she/system.h"
#include "ui/intern.h"
#include "ui/ui.h"
Expand Down Expand Up @@ -229,6 +231,32 @@ void App::initialize(const AppOptions& options)
}

she::instance()->finishLaunching();

#if !defined(_WIN32) && !defined(__APPLE__)
try {
she::Display* display = she::instance()->defaultDisplay();
she::SurfaceList icons;

for (const int size : { 32, 64, 128 }) {
ResourceFinder rf;
rf.includeDataDir(fmt::format("icons/ase{0}.png", size).c_str());
if (rf.findFirst()) {
she::Surface* surf = she::instance()->loadRgbaSurface(rf.filename().c_str());
if (surf)
icons.push_back(surf);
}
}

display->setIcons(icons);

for (auto surf : icons)
surf->dispose();
}
catch (const std::exception&) {
// Just ignore the exception, we couldn't change the app icon, no
// big deal.
}
#endif
}

void App::run()
Expand Down
39 changes: 0 additions & 39 deletions src/main/xpm_icon.c

This file was deleted.

46 changes: 45 additions & 1 deletion src/she/alleg4/alleg_display.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SHE library
// Copyright (C) 2012-2016 David Capello
// Copyright (C) 2012-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand Down Expand Up @@ -40,6 +40,7 @@
#elif defined ALLEGRO_UNIX

#include <xalleg.h>
#include <X11/Xatom.h>
#ifdef None
#undef None
#define X11_None 0L
Expand Down Expand Up @@ -532,6 +533,49 @@ void Alleg4Display::setTitleBar(const std::string& title)
set_window_title(title.c_str());
}

void Alleg4Display::setIcons(const SurfaceList& icons)
{
#ifdef ALLEGRO_UNIX

bool first = true;
for (Surface* icon : icons) {
auto display = _xwin.display;
auto window = _xwin.wm_window;
const int w = icon->width();
const int h = icon->height();

SurfaceFormatData format;
icon->getFormat(&format);

std::vector<unsigned long> data(w*h+2);
int i = 0;
data[i++] = w;
data[i++] = h;
for (int y=0; y<h; ++y) {
const uint32_t* p = (const uint32_t*)icon->getData(0, y);
for (int x=0; x<w; ++x, ++p) {
uint32_t c = *p;
data[i++] =
(((c & format.blueMask ) >> format.blueShift ) ) |
(((c & format.greenMask) >> format.greenShift) << 8) |
(((c & format.redMask ) >> format.redShift ) << 16) |
(((c & format.alphaMask) >> format.alphaShift) << 24);
}
}

Atom _NET_WM_ICON = XInternAtom(display, "_NET_WM_ICON", False);
XChangeProperty(
display, window, _NET_WM_ICON, XA_CARDINAL, 32,
first ? PropModeReplace:
PropModeAppend,
(const unsigned char*)&data[0], data.size());

first = false;
}

#endif
}

NativeCursor Alleg4Display::nativeMouseCursor()
{
return m_nativeCursor;
Expand Down
3 changes: 2 additions & 1 deletion src/she/alleg4/alleg_display.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SHE library
// Copyright (C) 2012-2016 David Capello
// Copyright (C) 2012-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand Down Expand Up @@ -33,6 +33,7 @@ namespace she {
bool isMaximized() const override;
bool isMinimized() const override;
void setTitleBar(const std::string& title) override;
void setIcons(const SurfaceList& icons) override;
NativeCursor nativeMouseCursor() override;
bool setNativeMouseCursor(NativeCursor cursor) override;
bool setNativeMouseCursor(const she::Surface* surface,
Expand Down
4 changes: 3 additions & 1 deletion src/she/display.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SHE library
// Copyright (C) 2012-2016 David Capello
// Copyright (C) 2012-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand All @@ -11,6 +11,7 @@
#include "gfx/point.h"
#include "she/display_handle.h"
#include "she/native_cursor.h"
#include "she/surface_list.h"

#include <string>

Expand Down Expand Up @@ -55,6 +56,7 @@ namespace she {
virtual bool isMinimized() const = 0;

virtual void setTitleBar(const std::string& title) = 0;
virtual void setIcons(const SurfaceList& icons) = 0;

virtual NativeCursor nativeMouseCursor() = 0;
virtual bool setNativeMouseCursor(NativeCursor cursor) = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/she/skia/skia_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ void SkiaDisplay::setTitleBar(const std::string& title)
m_window.setTitle(title);
}

void SkiaDisplay::setIcons(const SurfaceList& icons)
{
// TODO copy the Allegro impl
}

NativeCursor SkiaDisplay::nativeMouseCursor()
{
return m_nativeCursor;
Expand Down
3 changes: 2 additions & 1 deletion src/she/skia/skia_display.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SHE library
// Copyright (C) 2012-2016 David Capello
// Copyright (C) 2012-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand Down Expand Up @@ -48,6 +48,7 @@ class SkiaDisplay : public Display {
bool isMaximized() const override;
bool isMinimized() const override;
void setTitleBar(const std::string& title) override;
void setIcons(const SurfaceList& icons) override;
NativeCursor nativeMouseCursor() override;
bool setNativeMouseCursor(NativeCursor cursor) override;
bool setNativeMouseCursor(const she::Surface* surface,
Expand Down
21 changes: 21 additions & 0 deletions src/she/surface_list.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SHE library
// Copyright (C) 2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.

#ifndef SHE_SURFACE_LIST_H_INCLUDED
#define SHE_SURFACE_LIST_H_INCLUDED
#pragma once

#include <vector>

namespace she {

class Surface;

typedef std::vector<Surface*> SurfaceList;

} // namespace she

#endif

0 comments on commit 31bf851

Please sign in to comment.