summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--ranger/api/apps.py14
-rw-r--r--ranger/defaults/apps.py27
2 files changed, 28 insertions, 13 deletions
diff --git a/ranger/api/apps.py b/ranger/api/apps.py
index f1fcba62..62632df2 100644
--- a/ranger/api/apps.py
+++ b/ranger/api/apps.py
@@ -63,6 +63,10 @@ class Applications(FileManagerAware):
 			return True
 
 		for dep in deps:
+			if dep == 'X':
+				if 'DISPLAY' not in os.environ or not os.environ['DISPLAY']:
+					return False
+				continue
 			if hasattr(dep, 'dependencies') \
 			and not self._meets_dependencies(dep):
 				return False
@@ -132,10 +136,13 @@ class Applications(FileManagerAware):
 	@classmethod
 	def generic(cls, *args, **keywords):
 		flags = 'flags' in keywords and keywords['flags'] or ""
+		deps = 'deps' in keywords and keywords['deps'] or ()
 		for name in args:
 			assert isinstance(name, str)
 			if not hasattr(cls, "app_" + name):
-				setattr(cls, "app_" + name, _generic_wrapper(name, flags=flags))
+				fnc = _generic_wrapper(name, flags=flags)
+				fnc = depends_on(*deps)(fnc)
+				setattr(cls, "app_" + name, fnc)
 
 
 def tup(*args):
@@ -152,7 +159,10 @@ def tup(*args):
 def depends_on(*args):
 	args = tuple(flatten(args))
 	def decorator(fnc):
-		fnc.dependencies = args
+		try:
+			fnc.dependencies += args
+		except:
+			fnc.dependencies  = args
 		return fnc
 	return decorator
 
diff --git a/ranger/defaults/apps.py b/ranger/defaults/apps.py
index 10f0b3cf..802dca91 100644
--- a/ranger/defaults/apps.py
+++ b/ranger/defaults/apps.py
@@ -123,7 +123,8 @@ class CustomApplications(Applications):
 		args[0] += '2'
 		return args
 
-	@depends_on('feh')
+	# A dependence on "X" means: this programs requires a running X server!
+	@depends_on('feh', 'X')
 	def app_set_bg_with_feh(self, c):
 		c.flags += 'd'
 		arg = {11: '--bg-scale', 12: '--bg-tile', 13: '--bg-center',
@@ -132,7 +133,7 @@ class CustomApplications(Applications):
 			return 'feh', arg[c.mode], c.file.path
 		return 'feh', arg[11], c.file.path
 
-	@depends_on('feh')
+	@depends_on('feh', 'X')
 	def app_feh(self, c):
 		c.flags += 'd'
 		if c.mode is 0 and len(c.files) is 1: # view all files in the cwd
@@ -140,7 +141,7 @@ class CustomApplications(Applications):
 			return 'feh', '--start-at', c.file.basename, images
 		return 'feh', c
 
-	@depends_on('sxiv')
+	@depends_on('sxiv', 'X')
 	def app_sxiv(self, c):
 		c.flags = 'd' + c.flags
 		if len(c.files) is 1:
@@ -159,7 +160,7 @@ class CustomApplications(Applications):
 			return 'aunpack', '-l', c.file.path
 		return 'aunpack', c.file.path
 
-	@depends_on('file-roller')
+	@depends_on('file-roller', 'X')
 	def app_file_roller(self, c):
 		c.flags += 'd'
 		return 'file-roller', c.file.path
@@ -182,7 +183,7 @@ class CustomApplications(Applications):
 		files_without_extensions = map(strip_extensions, c.files)
 		return "java", files_without_extensions
 
-	@depends_on('totem')
+	@depends_on('totem', 'X')
 	def app_totem(self, c):
 		if c.mode is 0:
 			return "totem", c
@@ -198,20 +199,24 @@ class CustomApplications(Applications):
 			# aka "Open with..."
 			return "mimeopen", "--ask", c
 
+
 # Often a programs invocation is trivial.  For example:
 #    vim test.py readme.txt [...]
+#
 # This could be implemented like:
 #    @depends_on("vim")
 #    def app_vim(self, context):
 #        return "vim", context
-# Instead of creating such a generic function for each program, just add
-# its name here and it will be automatically done for you.
-CustomApplications.generic('vim', 'fceux', 'elinks', 'wine',
-		'zsnes', 'javac')
+#
+# But this is redundant and ranger does this automatically.  However, sometimes
+# you want to change some properties like flags or dependencies.  Add programs
+# that should only run in X this way here:
+CustomApplications.generic('fceux', 'wine', 'zsnes', deps=['X'])
 
-# By setting flags='d', this programs will not block ranger's terminal:
+# Add those which should only run in X AND should be detached/forked here:
 CustomApplications.generic('opera', 'firefox', 'apvlv', 'evince',
-		'zathura', 'gimp', 'mirage', 'eog', flags='d')
+		'zathura', 'gimp', 'mirage', 'eog', 'jumanji',
+			flags='d', deps=['X'])
 
 # What filetypes are recognized as scripts for interpreted languages?
 # This regular expression is used in app_default()
='#n299'>299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492