Files
wmaker/src/application.c
T

205 lines
5.0 KiB
C
Raw Normal View History

1998-09-29 22:36:29 +00:00
/*
1998-10-21 14:43:47 +00:00
* Window Maker window manager
2004-10-12 21:28:27 +00:00
*
2003-01-16 23:30:45 +00:00
* Copyright (c) 1997-2003 Alfredo K. Kojima
* Copyright (c) 1998-2003 Dan Pascu
2004-10-12 21:28:27 +00:00
*
1998-09-29 22:36:29 +00:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1998-09-29 22:36:29 +00:00
*/
#include "wconfig.h"
#include <X11/Xlib.h>
#include <string.h>
#include "WindowMaker.h"
#include "menu.h"
#include "window.h"
1999-04-10 19:32:34 +00:00
#ifdef USER_MENU
#include "usermenu.h"
2009-08-20 00:59:40 +02:00
#endif /* USER_MENU */
1998-09-29 22:36:29 +00:00
#include "appicon.h"
#include "application.h"
#include "appmenu.h"
#include "properties.h"
#include "workspace.h"
#include "dock.h"
2013-05-15 13:07:57 +02:00
#include "defaults.h"
1998-09-29 22:36:29 +00:00
/******** Local variables ********/
2009-08-20 00:59:40 +02:00
static WWindow *makeMainWindow(WScreen * scr, Window window)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
WWindow *wwin;
XWindowAttributes attr;
2012-06-01 19:06:59 +02:00
if (!XGetWindowAttributes(dpy, window, &attr))
2009-08-20 00:59:40 +02:00
return NULL;
wwin = wWindowCreate();
wwin->screen_ptr = scr;
wwin->client_win = window;
wwin->main_window = window;
wwin->wm_hints = XGetWMHints(dpy, window);
2012-06-01 19:06:59 +02:00
2009-08-20 00:59:40 +02:00
PropGetWMClass(window, &wwin->wm_class, &wwin->wm_instance);
wDefaultFillAttributes(wwin->wm_instance, wwin->wm_class, &wwin->user_flags,
&wwin->defined_user_flags, True);
2009-08-20 00:59:40 +02:00
XSelectInput(dpy, window, attr.your_event_mask | PropertyChangeMask | StructureNotifyMask);
return wwin;
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
WApplication *wApplicationOf(Window window)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
WApplication *wapp;
1998-09-29 22:36:29 +00:00
2009-08-20 00:59:40 +02:00
if (window == None)
return NULL;
if (XFindContext(dpy, window, w_global.context.app_win, (XPointer *) & wapp) != XCSUCCESS)
2009-08-20 00:59:40 +02:00
return NULL;
return wapp;
1998-09-29 22:36:29 +00:00
}
2009-08-20 00:59:40 +02:00
WApplication *wApplicationCreate(WWindow * wwin)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
WScreen *scr = wwin->screen_ptr;
Window main_window = wwin->main_window;
WApplication *wapp;
WWindow *leader;
1998-09-29 22:36:29 +00:00
2010-03-17 17:44:14 +01:00
if (main_window == None || main_window == scr->root_win)
2009-08-20 00:59:40 +02:00
return NULL;
{
Window root;
int foo;
unsigned int bar;
/* check if the window is valid */
2012-06-01 19:06:59 +02:00
if (!XGetGeometry(dpy, main_window, &root, &foo, &foo, &bar, &bar, &bar, &bar))
2009-08-20 00:59:40 +02:00
return NULL;
}
wapp = wApplicationOf(main_window);
if (wapp) {
wapp->refcount++;
if (wapp->app_icon && wapp->app_icon->docked &&
2012-06-01 19:06:59 +02:00
wapp->app_icon->relaunching && wapp->main_window_desc->fake_group)
wDockFinishLaunch(wapp->app_icon);
2009-08-20 00:59:40 +02:00
return wapp;
}
wapp = wmalloc(sizeof(WApplication));
wapp->refcount = 1;
wapp->last_focused = NULL;
2010-09-16 17:05:13 -04:00
wapp->urgent_bounce_timer = NULL;
2009-08-20 00:59:40 +02:00
wapp->last_workspace = 0;
wapp->main_window = main_window;
wapp->main_window_desc = makeMainWindow(scr, main_window);
if (!wapp->main_window_desc) {
wfree(wapp);
return NULL;
}
wapp->main_window_desc->fake_group = wwin->fake_group;
wapp->main_window_desc->net_icon_image = RRetainImage(wwin->net_icon_image);
2004-10-12 21:28:27 +00:00
2009-08-20 00:59:40 +02:00
leader = wWindowFor(main_window);
2012-03-30 15:35:19 +02:00
if (leader)
2009-08-20 00:59:40 +02:00
leader->main_window = main_window;
2012-03-30 15:35:19 +02:00
2009-08-20 00:59:40 +02:00
wapp->menu = wAppMenuGet(scr, main_window);
1999-04-10 19:32:34 +00:00
#ifdef USER_MENU
2009-08-20 00:59:40 +02:00
if (!wapp->menu)
wapp->menu = wUserMenuGet(scr, wapp->main_window_desc);
#endif
2009-08-20 00:59:40 +02:00
/* Set application wide attributes from the leader */
2009-08-20 00:59:40 +02:00
wapp->flags.hidden = WFLAGP(wapp->main_window_desc, start_hidden);
wapp->flags.emulated = WFLAGP(wapp->main_window_desc, emulate_appicon);
/* application descriptor */
XSaveContext(dpy, main_window, w_global.context.app_win, (XPointer) wapp);
2009-08-20 00:59:40 +02:00
2013-01-22 21:18:15 +01:00
create_appicon_for_application(wapp, wwin);
2012-06-18 11:15:19 +02:00
2009-08-20 00:59:40 +02:00
return wapp;
1998-09-29 22:36:29 +00:00
}
2013-10-08 00:56:45 +02:00
void wApplicationDestroy(WApplication *wapp)
1998-09-29 22:36:29 +00:00
{
2009-08-20 00:59:40 +02:00
WWindow *wwin;
if (!wapp)
return;
wapp->refcount--;
if (wapp->refcount > 0)
return;
2010-09-16 17:05:13 -04:00
if (wapp->urgent_bounce_timer) {
WMDeleteTimerHandler(wapp->urgent_bounce_timer);
wapp->urgent_bounce_timer = NULL;
}
2010-09-10 20:51:03 +04:00
if (wapp->flags.bouncing) {
/* event.c:handleDestroyNotify forced this destroy
and thereby overlooked the bounce callback */
wapp->refcount = 1;
return;
}
2013-10-08 00:56:45 +02:00
if (wapp->next)
wapp->next->prev = wapp->prev;
if (wapp->prev)
wapp->prev->next = wapp->next;
2009-08-20 00:59:40 +02:00
XDeleteContext(dpy, wapp->main_window, w_global.context.app_win);
2009-08-20 00:59:40 +02:00
wAppMenuDestroy(wapp->menu);
2010-09-10 20:51:07 +04:00
/* Remove application icon */
removeAppIconFor(wapp);
2009-08-20 00:59:40 +02:00
wwin = wWindowFor(wapp->main_window_desc->client_win);
wWindowDestroy(wapp->main_window_desc);
if (wwin) {
/* undelete client window context that was deleted in
* wWindowDestroy */
XSaveContext(dpy, wwin->client_win, w_global.context.client_win, (XPointer) & wwin->client_descriptor);
2009-08-20 00:59:40 +02:00
}
wfree(wapp);
1998-09-29 22:36:29 +00:00
}
void wApplicationActivate(WApplication *wapp)
{
if (wapp->app_icon) {
wIconSetHighlited(wapp->app_icon->icon, True);
2012-11-10 20:25:14 +01:00
wAppIconPaint(wapp->app_icon);
}
}
void wApplicationDeactivate(WApplication *wapp)
{
if (wapp->app_icon) {
wIconSetHighlited(wapp->app_icon->icon, False);
2012-11-10 20:25:14 +01:00
wAppIconPaint(wapp->app_icon);
}
}